【发布时间】:2011-02-01 10:40:56
【问题描述】:
我在 global.asx 的 Application_Error 子中查找 HttpExceptions
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ex As Exception = HttpContext.Current.Server.GetLastError()
If ex IsNot Nothing Then
If TypeOf (ex) Is HttpUnhandledException Then
If ex.InnerException Is Nothing Then
Server.Transfer("error.aspx", False)
End If
ex = ex.InnerException
End If
If TypeOf (ex) Is HttpException Then
Dim httpCode As Integer = CType(ex, HttpException).GetHttpCode()
If httpCode = 404 Then
Server.ClearError()
Server.Transfer("error_404.aspx", False)
End If
End If
End If
End Sub
我可以单步执行此代码并确认它确实命中了 Server.Transfer("error_404.aspx") 以及 error_404.aspx 的 Page_Load,但它显示的只是一个空白页面。
【问题讨论】:
-
确保向您的错误记录系统添加调用。如果发生未处理的异常,您想知道以便处理它。
标签: asp.net global-asax http-status-codes httpexception application-error