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!