应用 Asp.Net 过滤器更改 ScriptResource.axd 的内容

发布于 2024-12-11 03:34:47 字数 525 浏览 0 评论 0原文

我试图使用过滤器将某些文本插入到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琴流音 2024-12-18 03:34:47

如果这是不言而喻的,请原谅我,如果您只想将附加输出插入到 .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.

网白 2024-12-18 03:34:47

最后我关于压缩的假设是正确的。我设法通过禁用 ScriptResource.axd 文件内容来获取它。事实上,web.config 中有一个与此相关的配置,您可以在其中禁用压缩。就在本节中:

<system.web.extensions>
   <scripting>
      <scriptResourceHandler enableCompression="false" enableCaching="true" />
   <scripting>
<system.web.extensions>

现在我可以获取 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:

<system.web.extensions>
   <scripting>
      <scriptResourceHandler enableCompression="false" enableCaching="true" />
   <scripting>
<system.web.extensions>

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文