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