Applying a Asp.Net filter to change the content of ScriptResource.axd

858 views Asked by At

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.

2

There are 2 answers

0
Durden81 On BEST ANSWER

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

1
James Law On

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.