Search code examples
javascriptc#master-pageshttphandler

C# javascript files httphandler


I currently have a httpHandler in my application to change the path of the js files as they are requested. This works for some js files but not if they are requested from the master pages. Any ideas how to fix this?

Code:

Master Page:

<script type="text/javascript" src="somefile.js"></script>

Handler:

public class handler : IHttpHandler
{
     public void ProcessRequest(HttpContext context)
     {
           //DO STUFF
     }

     public bool IsReusable {get; private set; }
}

Web.config

<httpHandlers>
    <add verb="*" path="*.js" type="namespace.handler, namespace" />
</httpHandlers>
<handlers>
    <add name="JsHandler" path="*.js" verb="*" type="namespace.handler" resourceType="Unspecified" precondition="integratedMode" />
</handlers>

Solution

  • if your aim is just to change the requested file path, I would definitely prefer to declare an UrlRewrite rule into web.config over an IHttpHandler

    In this way, your paths will be managed directly from IIS (that should be more reliable as well faster); furthermore, you can then disable the RAMMFAR for your application.