应用 Asp.Net 过滤器更改 ScriptResource.axd 的内容
我试图使用过滤器将某些文本插入到 ScriptResource.axd 中,该文本是当我将 Js 放入 CompositeScript 元素时由 ScriptManager 生成的。
我发现这个任务几乎是不可能的。
用 Asp.Net 术语翻译的这个问题意味着我正在尝试过滤内置处理程序的输出(System.Web.Handlers.ScriptResourceHandler:没有源代码)。
当处理程序与请求关联时,我可以应用 HttpModules过滤甚至没有加载。因此,我尝试使用 HttpModule (即在 PostRequestHandlerExecute 中)从早期事件调用 System.Web.Handlers.ScriptResourceHandler 的“ProcessRequest”,然后在 PostReleaseRequestState 上应用过滤器...这给了我一个带有不可能的编码的字符串转换(也许 gzip 已经被使用了?)。
我想做的事情可能吗?您能给我一些关于如何进行的建议吗?
如果您需要更多信息或源代码,请告诉我。
I am trying to use a filter to insert certain text into ScriptResource.axd that is generated by the ScriptManager when I put my Js into a CompositeScript element.
I find this task next to impossible.
This problem translated in Asp.Net terms means that I am trying to filter the output from a builtin handler (System.Web.Handlers.ScriptResourceHandler: without source code)..
When an handler is associated with the request the HttpModules where I could apply the filtering are not even loaded. So I tried calling the "ProcessRequest" of System.Web.Handlers.ScriptResourceHandler from an earlier event using an HttpModule (i.e. in PostRequestHandlerExecute) and then appling the filter on PostReleaseRequestState... This gives me a string with an encoding that is impossible to convert (maybe gzip is already used?).
Is what I am trying to do even possible? Can you give me any suggestions on how you would proceed?
Let me know if you need more info or source code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这是不言而喻的,请原谅我,如果您只想将附加输出插入到 .axd (而不是更改输出),为什么不在引用 .axd 的页面中包含附加输出或另一个外部资源?如果您只需要添加额外的输出,这会更加有效。
Forgive me if this goes without saying, if you're only looking to insert addition output to the .axd (as opposed to altering the output), why don't you just include the additional output in the page that references the .axd or another external resource? This would be far more efficient if simply adding additional output is all you require.
最后我关于压缩的假设是正确的。我设法通过禁用 ScriptResource.axd 文件内容来获取它。事实上,web.config 中有一个与此相关的配置,您可以在其中禁用压缩。就在本节中:
现在我可以获取 PostReleaseRequestState 中 HttpModule 中的内容,如果我愿意,我现在可以在替换字符串后进行一些 GZip 压缩。我将做一些测试,看看我是否还需要禁用缓存......
In the end my supposition about compression was right. I managed to get the ScriptResource.axd file content by disabling it. In fact there is a configuration about this in the web.config where you can disable the compression. It is in this section:
Now I am able to get the content in the HttpModule in PostReleaseRequestState and if I want I can now do some GZip compression after I substitute the strings. I will do some testing to see if I also need to disable the caching...