Folder requests not being handled by ASP.NET

trapattoni

New Member
I'm attempting to write a custom HttpHandler in order to handle all of my 404 errors. The handler is catching and handling all file types that I've specified but for some reason it isn't handling requests for folders, i.e. if I put in mysite.com/foo/bar.html or mysite.com/foo/bar.aspx it handles it and shows the right error page, but if I enter mysite.com/foo/ it shows a completely blank page, with no source code or anything. Here's the code for the handler: \[code\]public class RedirectHttpModule :IHttpHandler, IHttpModule {public RedirectHttpModule() { // // TODO: Add constructor logic here //}public void Dispose() { }public void Init(HttpApplication context) { context.Error += new EventHandler(ErrorHandler);}private void ErrorHandler(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; application.Context.Response.TrySkipIisCustomErrors = true; Exception lastError = application.Server.GetLastError(); HttpException ex = lastError as HttpException; ILog _logger = LogManager.GetLogger(typeof(Page)); string page = "~/404.aspx"; if (ex != null) { application.Server.ClearError(); application.Context.Handler = System.Web.UI.PageParser.GetCompiledPageInstance(page, application.Server.MapPath(page), application.Context); string username = application.Context.User.Identity.Name; if (!String.IsNullOrEmpty(username)) _logger.ErrorFormat("HTTP Error {0}: {1} Username: {2}", ex.GetHttpCode().ToString(), ex.Message, username); else _logger.ErrorFormat("HTTP Error {0}: {1}", ex.GetHttpCode().ToString(), ex.Message); } else { application.Context.Handler = System.Web.UI.PageParser.GetCompiledPageInstance(page, application.Server.MapPath(page), application.Context); }}public bool IsReusable { get { return true; }}public void ProcessRequest(HttpContext context) { if (!File.Exists(context.Request.PhysicalPath)) { throw new HttpException(404, String.Format("The file or directory {0} does not exist.", context.Request.PhysicalPath)); } else { context.Response.TransmitFile(context.Request.PhysicalPath); }}\[/code\]}and here's the relevant sections of the Web.config: \[code\]<handlers> <add name="html-to-aspx-isapi" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" /> <add name="html-to-aspx" path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" preCondition="integratedMode" /> <add name="htm-to-aspx-isapi" path="*.htm" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" /> <add name="htm-to-aspx" path="*.htm" verb="*" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" preCondition="integratedMode" /> <add name="asp-to-aspx-isapi" path="*.asp" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" /> <add name="asp-to-aspx" path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" preCondition="integratedMode" /> <add name="RedirectHttpModule" modules="RedirectHttpModule" preCondition="" path="*" verb="*" resourceType="Either"/></handlers><modules runAllManagedModulesForAllRequests="true"> <add name="RedirectHttpModule" type="RedirectHttpModule" preCondition="managedHandler"/></modules>\[/code\]For whatever reason, even though it's running Integrated instead of Classic, if I remove the first 6 handlers, it will no longer handle html, htm or asp requests with ASP.NET. I'm beginning to suspect there's some sort of configuration problem. Any ideas?Thanks in advance for all your help.
 
Back
Top