The code is very simple. I have posted what I have written in ordinary times for you to see:
If (bresult = true) // The logon username and password are correct.
{
// Save the Login User Name
Session ["loginuser"] = formatstring. Replace (txtloginuser. Text); // The value is assigned to the session. I have performed some security operations on the logged-on user.
// Go to the Management Homepage
Response. Redirect ("admin_index.aspx ");
}
Else
{
Lblerr. Text = message. Show ("incorrect user name or password! ");
Showvalidate (); // re-display the verification code
}
Then how can I determine whether to log on to the page? The code is simpler, as follows:
If (session ["loginuser"] = NULL) // the above session name uses loginuser. The name here must be the same as the above one. You can change it as needed to keep it consistent, note: There is no tostring () after session ["loginuser"]. If you add it, an error will occur.
{
Response. Redirect ("login. aspx"); // if the session is empty, go to the login page.
}
The session may be lost. For the solution, see another article I wrote:
Solution to session loss after login
Http://blog.csdn.net/kgdiwss/archive/2005/03/04/310724.aspx