asp.net prevent users from skipping login interface _ practical Tips
Source: Internet
Author: User
1. Add the following code after checking in the landing page for successful code
session["UserID"] = TxtUserID.Text.Trim ();
Or
session["UserID"] = "OK";
For example, in my Login.aspx.cs Login button response event the code is as follows:
if (Baseclass.checkuser (TxtUserID.Text.Trim (), TxtPwd.Text.Trim ()))
{
session["UserID"] = TxtUserID.Text.Trim ();
Response.Redirect ("main.aspx");
}
Else
{
Response.Write ("<script>alert" (' Username or password error '); location= ' Login.aspx ' </script> ");
}
2. Then add the following code at the beginning of the Page_Load of each page:
if (session["UserID"] = = NULL | | session["UserID"]. ToString () = "")
{
Response.Write ("<script language= ' javascript ' >window.top.location.href= ' login.aspx ';</script>");
}
For example, the Page_Load code in my Main.aspx.cs contains the following:
protected void Page_Load (object sender, EventArgs e)
{
if (session["UserID"] = = NULL | | session["UserID"]. ToString () = "")
{
Response.Write ("<script language= ' javascript ' >window.top.location.href= ' login.aspx ';</script>");
}
if (! IsPostBack)
{
}
}
3. Try, hehe,,,
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