我遇到了我构建的自定义错误处理程序的麻烦.它应该是一个HttpModule,但当我将它添加到我的web.config的system.webServer / modules标签时,它不会被启动.
这是我的web.config部分:
<system.webServer> <modules> <add name="AspExceptionHandler" type="Company.Exceptions.AspExceptionHandler,Company.Exceptions" preCondition="managedHandler" /> </modules> </system.webServer>
这是我的HttpModule中的代码:
using System; using System.Web; using Company.Settings; using System.Configuration; namespace Company.Exceptions { public class AspExceptionHandler : IHttpModule { public void Dispose() { } public void Init(HttpApplication application) { application.Error += new EventHandler(ErrorHandler); } private void ErrorHandler(object sender,EventArgs e) { HttpApplication application = (HttpApplication)sender; HttpContext currentContext = application.Context; // Gather information5 Exception currentException = application.Server.GetLastError(); String errorPage = "http://www.mycompaniesmainsite.com/error.html"; HttpException httpException = currentException as HttpException; if (httpException == null || httpException.GetHttpCode() != 404) { currentContext.Server.Transfer(errorPage,true); } else { application.Response.Status = "404 Not Found"; application.Response.StatusCode = 404; application.Response.StatusDescription = "Not Found"; currentContext.Server.Transfer(errorPage,true); } } } }
有人可以向我解释我的错误,以及IIS 7集成管理管道模式的工作原理吗?因为我发现的大部分答案都是为IIS 6配置HttpModule.