HTTP Handler and 404 error for a custom file extension

mbbkagb

New Member
There is something that is not so clear to me with regards to Custom HTTP Handler.I have created a \[code\]ScriptTranslator\[/code\] HTTP Handler according to this blog postI have registered the handler in my web.config file in the following way:\[code\]<system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true" /> <handlers> <add name="ScriptTranslatorHandler" path="*.js.axd" verb="*" type="CamelotShiftManagement.HttpHandlers.ScriptTranslator" /> </handlers></system.webServer>\[/code\]I have also added an \[code\]IgnoreRoute\[/code\] command to my global.asax so the web-app could fire up the handler according to the we.config file.\[code\]routes.IgnoreRoute("{resource}.js.axd/{*pathInfo}");\[/code\]The handler is suppose to translate a JS file reference from my html file, so I modify my script reference and add an \[code\]axd\[/code\] extension at the end.The handler receives a request and searches for the file without the axd extention to get the script content that is need to be translated, here is the basic \[code\]ProccessRequest\[/code\] action :\[code\]public void ProcessRequest(HttpContext context){ string relativePath = context.Request.AppRelativeCurrentExecutionFilePath.Replace(".axd", string.Empty); string absolutePath = context.Server.MapPath(relativePath); string script = ReadFile(absolutePath); string translated = TranslateScript(script,CultureInfo.CurrentCulture); context.Response.Write(translated); Compress(context); SetHeadersAndCache(absolutePath, context);}\[/code\]So in my html file I modify only the reference of the script tag, there is not actual file called \[code\]myscript.js.axd\[/code\] there is a file called \[code\]myscript.js\[/code\].I get a 404 error.I am frailly new to creating and using a custom Http Handler and I don't know what to expect from the usage. The referenced blog post implies that there should be not actual .js.axd file in the code and the request for the script reference will reroute to the handler and process the actual .js file by using the first 2 lines in the code I provided before that.I wounder weather or not setting a custom HTTP handler should run the handler code first and only then throw a 404 error,or should I create a dummy myScript.js.axd file to support the handlers action?
 
Back
Top