I'm using #4 on this tutorial to do authentication.
If I login, and then manually navigate to the page I need I do not get logged out. However, if I use Response.Redirect()
or Server.Transfer()
my user is instantly logged out.
Here is my code
protected void Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
{
string userName = Login1.UserName;
string password = Login1.Password;
bool result = UserLogin(userName, password); // This method executes SQL on my own database and returns true if the username and password work
if ((result))
{
e.Authenticated = true;
// Redirect users to some page
Response.Redirect("/home.aspx"); // THIS CAUSES A LOGOUT
}
else
{
e.Authenticated = false;
}
}
The problem here is that Response.Redirect immediately cancels all remaining code in the current page flow so the code that would normally use the Authenticated flag to indicate the user is authenticated is never executed.
If you are using the Login control, you can use the DestinationPageURL property in the control to automatically redirect to the Home.aspx page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.