asp.net – 用于集成的IIS 7的自定义HttpModule
发布时间:2020-05-24 12:13:53 所属栏目:asp.Net 来源:互联网
导读:我遇到了我构建的自定义错误处理程序的麻烦.它应该是一个HttpModule,但当我将它添加到我的web.config的system.webServer / modules标签时,它不会被启动. 这是我的web.config部分: system.webServer modules add name=AspExceptionHandler type=Co
|
我遇到了我构建的自定义错误处理程序的麻烦.它应该是一个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. 解决方法从我所看到的你走在正确的轨道上.您是否确定您的站点的应用程序池设置为Managed Pipeline模式?此外,如果您使用内置的Visual Studio Web服务器(Cassini)进行测试,那么< system.webServer>部分将被忽略.如果您希望从那里加载模块,则需要IIS7或IIS7.5 Express. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- ASP.NET网站内存使用率相当高
- 如何在ASP.NET 5中添加一个TypeScript绝对类型的
- asp.net – 在Web.Config的Location Path元素中指
- asp.net-core – 如何在ASP.NET 5中使用“旧”依
- asp.net-mvc – 使用ASP.NET MVC的RESTful Web服
- asp.net-mvc – 建议在开发期间使用nhibernate设
- asp.net-mvc – 在Asp.Net MVC应用程序中使用Str
- 在ASP.NET中如何识别/处理404异常?
- asp.net-mvc – 使用依赖注入来组织ASP.Net MVC解
- 如何在ASP.NET成员资格中访问UserId而不使用Memb
热点阅读
