asp.net – 用于集成的IIS 7的自定义HttpModule
发布时间:2020-12-16 04:23:16 所属栏目:asp.Net 来源:网络整理
导读:我遇到了我构建的自定义错误处理程序的麻烦.它应该是一个HttpModule,但当我将它添加到我的web.config的system.webServer / modules标签时,它不会被启动. 这是我的web.config部分: system.webServer modules add name="AspExceptionHandler" type="Company.E
我遇到了我构建的自定义错误处理程序的麻烦.它应该是一个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-core – 来自带有Entity Framework Core的Data Tie
- asp.net-mvc-4 – Razor MVC,在哪里可以通过母版页面,部分视
- asp.net – 如何强制使用default.aspx而不是www.domain.com
- asp.net-mvc – 更新实体框架MVC中的子实体
- asp.net – 如何更改.ASPX自动格式化设置(Visual Studio)
- ASP.NET 1.1到4.0迁移:事件不工作
- asp.net-mvc – 使用Razor在ASP.NET MVC3中的文件上传控件
- 来自asp.net服务器端的确认框
- 如何在ASP.net runat =’server’标记中使用传统的HTML id属
- asp.net-mvc – Html.RenderPartial和Html.Render之间的区别
推荐文章
站长推荐
- asp.net-mvc – Visual Studio 2015异步变量未在
- asp.net页面生命周期
- asp.net – Web.Debug.config没有将连接字符串转
- asp.net-mvc – 仅允许来自特定电子邮件域的注册
- asp.net – 如何在OnActionExecuting中获取当前路
- asp.net – 将Salesforce.com与.NET Server C集成
- asp.net-mvc – 使用MVC w / Bundles时CSS中的相
- .net – 什么是dnu换行?
- asp.net-mvc – MVC:创建应用程序基本URL链接的
- asp.net+ajaxfileupload.js 实现文件异步上传代码
热点阅读