代码之家  ›  专栏  ›  技术社区  ›  kenwarner

应用程序中的server.transfer(“error_404.aspx”)返回空白页

  •  2
  • kenwarner  · 技术社区  · 15 年前

    我在global.asx的application_error sub中查找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_.aspx”)以及error_.aspx的页面加载,但它显示的只是一个空白页面。

    3 回复  |  直到 12 年前
        1
  •  4
  •   Bryan    15 年前

    正在清除响应缓冲区吗?您不知道已经存在什么,因为您正在应用程序中执行此操作。transfer只是将新页面生成的内容附加到现有响应上。显然,这会造成一些问题。

        2
  •  0
  •   LesterDove    15 年前

    如果你改变 Server.Transfer 到A Response.Redirect ?(您可能必须从global.asax中的位置使用httpcontext.current前缀。)

    我不确定服务器.transfer是否适合您所做的工作,因为您实际上要求IIS将global.asax URL呈现给浏览器。

        3
  •  0
  •   JimmyPena Alex K.    12 年前

    我认为如果发生错误,服务器。传输不会启动。

    Server.Transfer 不是个好办法。尝试用 Response.Redirect . 它应该有用。

    如果你有任何例外,是否有任何要求,以维持国家?如果没有,就跟着 Response.Redirect .