我寻找HttpExceptions在我global.asx

的子的Application_Error
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中,但所有这表明是一个空白页。

有帮助吗?

解决方案

您清除响应缓冲区?你不知道什么是已经存在的,因为你是在Application_Error事件捕获所有这样做。 Server.Transfer的只是追加任何新的页面生成到现有的响应。显然,这可能会造成一些问题。

其他提示

是否如果你改变了Server.TransferResponse.Redirect工作? (您可能需要使用HTTPContext.Current前缀从你在Global.asax的地方。)

我不知道,一个Server.Transfer的是你在做什么的情况下是一个好主意,因为你实际询问IIS呈现在Global.asax网址到浏览器。

我想,如果发生一些错误,Server.Transfer方法不会火。

Server.Transfer的是不是一个很好的方法。尝试使用的Response.Redirect 。它应该工作。

如果您有任何的例外是有维护国家什么要求吗?如果没有,去Response.Redirect

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top