Global.asax Application_Error问题
问题描述:
我想处理Global.asax的Application_Error事件中的未捕获异常。目前,它看起来像Global.asax Application_Error问题
Sub Application_Error(ByVal sender as object, ByVal e as EventArgs)
Server.ClearError()
Response.Redirect("~/ErrorPages/GenericError.aspx")
End Sub
抛出一个全新的例外在另一页的Page_Load中与
Throw New Exception()
什么最终实际发生的情况是,执行从来没有离开源页面,并抛出默认ASP错误引用我的例外。为什么它不被发送到我的错误页面?
编辑:固定Response.Redirect
。现在的样子:
Response.Redirect("http://mysite/ErrorPages/GenericError.aspx")
还提出,由krshekhar建议建议改变我的web.config
文件。虽然我现在被发送到我的错误页面,但它使用的是默认重定向,而不是我在Application_Error
中提供的重定向。任何其他想法?
答
的解决方案应该是customErrors mode="On"
唯一的问题查找您qustion是customError web.config中的条目应该是如下
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
...
</customErrors>
</system.web>
</configuration>
帮助链接
ASP.NET custom error page - Server.GetLastError() is null
CustomErrors mode="Off"
有你在web.config中打开或关闭了CustomerErrors? – tomasmcguinness 2013-02-08 16:38:46
使用像'Response.Redirect'这样的FYI会抛出一个'ThreadAbortException'。 [MSDN entry](http://msdn.microsoft.com/en-us/library/a8wa7sdt%28v=vs.100%29.aspx) – MikeSmithDev 2013-02-08 17:01:06