I'm using an Http Handler to localize javascript files used in my application: see: Localize text in JavaScript files in ASP.NET
I want to use the handler provided so I did the following:
1) Ignored routes using this code in Global.asax - I have added the routes.IgnoreRoute("{resource}.js.axd/{*pathInfo}");
line of code to the RegisterRoutes
method so it looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.js.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
2) I have added <add path="*.js.axd" verb="*" type="CamelotShiftManagement.HttpHandlers.ScriptTranslator" />
line to my web.confing file in the Views folder so it looks like this:
<system.web>
<httpHandlers>
<add path="*.js.axd" verb="*" type="CamelotShiftManagement.HttpHandlers.ScriptTranslator" />
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
And yet I get a Page not found error when I try to access the following URL:
http://camelotshiftmanagement.com/Scripts/Administration/OrganizationalStructure.js.axd
What am I doing wrong here ?
Progress: Okay, so I found out an awkward mistake i made... For some reason I thought that when adding a Handler for
*.js.axd
will find the file but actually it did not because the file was named OrganizationalStructure.js
witout the .axd
extension.
So that is the reason for the 404 error but now i get a different error from the server and I need your help again.
accessing http://camelotshiftmanagement.com/Scripts/Administration/OrganizationalStructure.js.axd
produced a different error this time: 404.17 The requested content appears to be script and will not be served by the static file handler.
Additional error information
Server Error in Application "CAMELOTSHIFTMANAGEMENT.COM"
Internet Information Services 7.5
Error Summary
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.
Detailed Error Information
Module: "StaticFileModule"
Notification: "ExecuteRequestHandler"
Handler: "StaticFile"
Error Code: "0x80070032"
Requested URL: "http://camelotshiftmanagement.com:80/Scripts/Administration/OrganizationalStructure.js.axd"
Physical Path: "C:\Code\CamelotShiftManagement\CamelotShiftManagement\Scripts\Administration\OrganizationalStructure.js.axd"
Logon Method: "Anonymous"
Logon User: "Anonymous"
Most likely causes:
The request matched a wildcard mime map. The request is mapped to the static file handler. If there were different pre-conditions, the request will map to a different handler.
Things you can try:
If you want to serve this content as a static file, add an explicit MIME map.
Well I am way over my league here... I do not understand why my custom handler is not called and instead a StaticFile handler is called.