【发布时间】:2015-06-07 10:23:25
【问题描述】:
去年,我们将 Web 应用程序移至新服务器。以下是迁移前的系统/应用程序配置规范:
- Windows Server 2003
- IIS 6.0
- ASP.NET 4.0
- 网络表单
以下是移至新服务器后的规格:
- Windows Server 2008
- IIS 7.5
- ASP.NET 4.5.1
- WebForms/MVC 5 混合(感谢 VS 2013)
问题是,在环境因移动而发生剧烈变化后,Global.asax 中的 Application_Error 事件不再像以前那样触发。我遇到了很多关于此的问题(请参阅此问题的结尾),但似乎没有一个解决方案有效。它们也很老了,所以我认为 SE 应该提供一些关于这个主题的更新答案。
我想做什么:
如果抛出特定异常,我想导航到特定错误页面。否则,转到我的 web.config 中定义的error.aspx。自搬迁以来,我没有对 web.config 或代码进行任何更改。这是 Application_Error 事件:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
If TypeOf (Server.GetLastError) Is System.Web.HttpRequestValidationException Then
NavigateToErrorPage("Display special error message here")
End If
End Sub
customErrors 在 web.config 中:
<customErrors mode="RemoteOnly" defaultRedirect="error.aspx" />
那么我需要做什么才能让我的应用程序在 IIS 7.5 中的行为与在 IIS 6 中的行为相同?
编辑:我会注意到在 localhost 下本地运行我的应用程序时会触发 Application_Error 事件。
我发现的其他问题在这里无法帮助我:
Application_Error event global.asax not getting triggered
global.asax Application_Error not firing
Application_Error not firing when customerrors = "On"
Is global.asax Application_Error event not fired if custom errors are turned on?
【问题讨论】:
标签: asp.net asp.net-mvc-5 iis-7.5 iis-6 global-asax