【发布时间】: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