Tips for ASP. NET background Logon

Source: Internet
Author: User

For some pages in the background that need to be accessed only after logon, do you always determine whether the values in the session or cookie are saved during logon! If there are dozens of such pages in the background, you have to judge each time and feel really annoyed. Here I will share a solution I know! Haha, and Daniel moxiao, I just want beginners to learn about. NET kids shoes. A Demo. aspx Page we created is inherited from the Page class, for example:

To achieve the expected results, let's create a new CheckLoginedPage class:


Now let our CheckLoginedPage class inherit from the Page class:

Next, you need to move the cursor down in the CheckLoginedPage class. The Code is as follows:
Copy codeThe Code is as follows:
Public class CheckLoginedPage: System. Web. UI. Page
{

Public CheckLoginedPage ()
{
Load + = CheckLogin; // The constructor loads the CheckLogin method.
}

/// <Summary>
/// Determine whether to log on
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Public void CheckLogin (object sender, EventArgs e)
{
If (Session ["XXXX"] = null) // The Session value is saved during logon.
{
Response. Redirect ("**. aspx"); // if it is null, go to the page to be transferred
}
}

}

After completing the preceding steps, you only need to make the pages that must be logged on to be accessed inherit from the CheckLoginedPage class:

Okay, that's all. If there is something wrong, I hope you can correct it! If you have never used this method, hurry up!

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.