Login status remains:
First do a login interface, click the login button
protected void Page_Load (object sender, EventArgs e) {button1.click + = Button1_click;// login button press two times tab void button1_click ( sender, EventArgs e) { // first remove the username and password to the database class
bool isOK = new
USERSDA (). Select (Textbox1.text,textbox2.text);
if (isOK) {
If you can get on board, save the name in the cookie object before jumping to the page to record the user name
response.cookies["User"]. Value = TextBox1.Text;
if (checkbox1.checked)
{
response.cookies["User"]. Expires=datetime.now.adddays (15);
}
Response.Redirect ("main.aspx");//Jump page
}
When jumping from the login interface to the main interface, put a lable in the main interface to display the user name;
Login Front Code: <asp:checkbox id= "CheckBox1" runat= "server"/><label for= "CheckBox1" > Remember login status 15 days </label ><br/><br/>
Main Interface Background code:
protected voidPage_Load (Objectsender, EventArgs e) { //first of all, take the value of cookies if(request.cookies["User"] !=NULL)//not empty, with a value{Label1.Text= request.cookies["User"]. Value +", you are welcome"; } Else{Response.Redirect ("denglu.aspx"); }
There is a login to sign out:
A button is placed in the main interface: Log out and clear the cookies.
button1.click += button1_click; void button1_click (object Span style= "color: #000000;" > sender, EventArgs e) { // 1, clear cookies< /span> response.cookies[ "]. Expires = DateTime.Now.AddDays (-1 ) ; Only negative numbers // 2, refresh the page, or skip to the login page Resp Onse. Redirect ( " ); }
Login status remains:
Cookies
A piece of text saved on the hard drive of the user's computer
The HTTP protocol includes a browser that allows the site to temporarily store data in the form of cookies on the user's computer.
If no save time is set, session cookies
1, if you do not refresh the page in 20 minutes, then this cookie will be automatically deleted
2, when the current access connection is interrupted, such as closing the browser, then the cookies will be automatically deleted
Role:
Keep the user's login status
WebForm---Login status hold (cookies built-in objects)