Search code examples
asp.nethttphandlerhttpmodulescriptmanagerscriptresource.axd

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


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.


Solution

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