Visual studio 2010 Visual Studio 2010 Visual basic页面重定向不工作

Visual studio 2010 Visual Studio 2010 Visual basic页面重定向不工作,visual-studio-2010,response.redirect,Visual Studio 2010,Response.redirect,在系统的第二个页面上,我检查用户ID。如果没有在第一个页面上输入用户ID(他们可能直接跳到第二个页面),我会将他们重定向到错误页面 问题是在那一点上一切都悬而未决 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Session("userName") Is Nothing Or Session("userName") = ""

在系统的第二个页面上,我检查用户ID。如果没有在第一个页面上输入用户ID(他们可能直接跳到第二个页面),我会将他们重定向到错误页面

问题是在那一点上一切都悬而未决

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If (Session("userName") Is Nothing Or
        Session("userName") = "") Then
        Response.Redirect("Error.aspx")
    End If

End Sub

尝试:

p、 不要像这样从会话中获取值。使用:

现在检查用户名

Server.Transfer("Error.aspx", True)
Dim username as String = CType(Session.Item("userName"), String)
Dim username as String = CType(Session.Item("userName"), String)
If String.IsNullOrEmpty(username) Then 
        Response.Redirect("Error.aspx")
Dim username as String = CType(Session.Item("userName"), String)
If String.IsNullOrEmpty(username) Then 
         Server.Transfer("Error.aspx", True)