1

在我的应用程序中,我为 404 编写了以下代码。

   Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    Dim exc As Exception
            Dim readdInfo As New NameValueCollection

            exc = Server.GetLastError()
            Dim httpCode As Integer = CType(exc, HttpException).GetHttpCode()
            If httpCode = 404 Then
                If TypeOf Context.CurrentHandler Is System.Web.UI.Page Then
                    Context.Server.Transfer("404.aspx")
                    Context.Response.Flush()
                    Context.Response.End()
                Else
                    Context.RewritePath("404.aspx")
                    Context.Response.Clear()
                    Context.Response.ClearContent()
                    Context.Response.ClearHeaders()
                    **Context.CurrentHandler.ProcessRequest(Context)**
                    Context.Response.Flush()
                    Context.Response.End()
                End If
    End If
 End Sub

但是当我尝试运行上面的程序时,我得到 Context.CurrentHandler是空异常。如果我保留 Response.Redirect 代替 Server.Transfer 我得到 301 标头。我使用http://404checker.com/full-header-checker进行标题检查

4

1 回答 1

1

不确定您要做什么,但 Response.Redirect 是 302:

HTTP/1.1 302 Object moved

您的 Context.CurrentHandler 检查在 Server.Transfer 之前,因此与您的空异常无关。

于 2012-04-10T18:49:35.260 回答