Search code examples
iisiis-7handlerasp.net-4.0

Running JS files through the same server handler as ASPX files..


We are using IIS 7. We need to have our JS files be processed by the same handler as aspx files, so that we can do some server-side string manipulation on them before being sent down to the browser.

We use IIS7, .NET 4, integrated pipeline mode.

We tried adding a script map, as well as a managed handler to the handler mappings to catch *.js using System.Web.UI.PageHandlerFactory.

It's being caught, but we're getting 500 errors when opening the js page.

Are we going about this the wrong way? Not quite sure what we're missing.


Solution

  • Check out this posting.

    However, since you're wanting to run .JS files through it, you'll need to remove the default JS build provider by adding this line:

    <remove extension=".js" />
    

    So that the buildProviders block looks like this:

    <buildProviders> 
        <remove extension=".js" />
        <add extension=".js" type="System.Web.Compilation.PageBuildProvider" /> 
    </buildProviders>