Asp. NET uses session to determine whether a user is logged in

Source: Internet
Author: User

Asp. NET uses session to determine whether a user is logged in

The following is a reference fragment:
if (bresult = = true)//login username and password correct
{
Save logged in User name
session["Loginuser"] = Formatstring.replace (Txtloginuser.text); This is where the session is assigned a value. I have some security handling for the logged-in user.
Go to admin Home
Response.Redirect ("admin_index.aspx");
}
Else
{
Lblerr.text = Message.show ("Wrong username or password!");
Showvalidate (); Re-display verification code
}
So how do you decide to log in on the page? The code is simpler, as follows:
if (session["loginuser"] = = null)//above session name with Loginuser, the name here to and above the same, you can change, keep the same line, note: session["Loginuser"] behind, No ToString () Oh, if you add it, you'll make a mistake.
{
Response.Redirect ("Login.aspx"); If the session is empty, go to the landing page.
}



Related Article

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.