In ASP. NET, how does one use session to determine whether a user is logged on? (Original)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.