【问题标题】:Response.Redirect only refreshes page, does not redirect user to new pageResponse.Redirect 仅刷新页面,不将用户重定向到新页面
【发布时间】:2016-05-16 16:34:04
【问题描述】:

我的页面上有以下按钮的标记代码:

<asp:Button ID="LoginButton" runat="server"
                                     CssClass="ButtonColor" 
                                     Text="Log In" 
                                     Width="75px" height="20px"
                                     OnClientClick="setCookie();"
                                     OnClick="LoginButton_Click"
                                     />

这里是 LoginButton_Click:

    Protected Sub LoginButton_Click(sender As Object, e As EventArgs)
    'Check if username / password is valid
    ' Dim gn = New BA_Shared_Object_Library.Data.SQLServer("GetNext 2.0 (DEV)", BA_Shared_Object_Library.Data.SQLServer.ConnectionConfigurationTypeEnum.DatabaseName)

    Dim CredentialsValid = Membership.ValidateUser(UserName.Text, Password.Text)

    If (CredentialsValid) Then
        'Add User Session stuff
        Session.Add("MFUserName", UserName.Text)
        Session.Add("MFPW", Password.Text)
        Response.Redirect("MFACheck.aspx", False)
    Else


    End If

End Sub

当它执行时,我单步执行代码并点击 Response.Redirect 行。但是,页面只是刷新,而不是重定向。我做错了什么?

我试过Response.Redirect("MFACheck.aspx", False)

我试过Response.Redirect("~/MFACheck.aspx", False)

我错过了什么?

谢谢

【问题讨论】:

  • 试试Response.Redirect("~/MFACheck.aspx", true);。见Response.Redirect MSDN Reference
  • 您可能会被重定向回登录页面,因为您实际上还没有登录用户。使用FormsAuthentication.RedirectFromLoginPage 方法(将创建身份验证cookie)或在重定向之前使用FormsAuthentication.SetAuthCookie 手动添加cookie。

标签: asp.net .net vb.net webforms


【解决方案1】:

尝试将 Response.Redirect 设置为 True

Response.Redirect("MFACheck.aspx", False)

如果这不是问题,请确保在登录时使用正确的用户名和密码凭据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-07
    • 2011-09-24
    • 2019-01-05
    • 1970-01-01
    • 2020-12-31
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多