The way in which the state is stored in the program is a cookie that was previously written about ViewState. Now continue to summarize the way cookies
New test Page Login
<%@ Page language="C #"autoeventwireup="true"codefile="Login.aspx.cs"inherits="Login"%><! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Server"> <title></title> <script type="Text/javascript">function Checksubmit () {varuser = document.getElementById ("txtname"); varReg =/^\s*$/; if(Reg.test (user.value)) {alert ("Please enter the user name! "); User.focus (); return false; } varPWD = document.getElementById ("txtpwd"); if(Reg.test (pwd.value)) {alert ("Please enter your password! "); Pwd.focus (); return false; } return true; } </script>"Form1"runat="Server">Login Name:<asp:textbox id="txtname"runat="Server"></asp:TextBox>Password:<asp:textbox id="txtpwd"runat="Server"></asp:TextBox> <asp:button id="Btn_login"runat="Server"text="Login"onclick="Btn_login_click"onclientclick="return Checksubmit ()"/> </form></body>Login.aspxBackground. cs file
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data; Public Partial classlogin:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { } protected voidBtn_login_click (Objectsender, EventArgs e) { stringName =TxtName.Text.Trim (); stringPWD =TxtPwd.Text.Trim (); if(Name = =string. Empty) {MessageBox.Show ( This,"Please enter the user name! "); return; } if(pwd = =string. Empty) {MessageBox.Show ( This,"Please enter your password! "); return; } if(Name = ="Test"&& pwd = ="123456") {RESPONSE.COOKIES.ADD (NewHttpCookie ("Comid"," -")); response.cookies["Comid"]. Expires = DateTime.Now.AddDays ( -);//set expiration time, 30 daysResponse.Redirect ("Get cookies.aspx"); } Else{MessageBox.Show ( This,"User name password is wrong! "); } } }Get cookies.aspx page Background
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data; Public Partial classGet cookies:system.web.ui.page{ Public stringComid =""; protected voidPage_Load (Objectsender, EventArgs e) { if(request.cookies["Comid"] !=NULL&& request.cookies["Comid"]. Value! ="") {Comid= request.cookies["Comid"]. Value;//get the comid deposited} MessageBox.Show ( This,"Login id="+comid); }}
When I log in the time deposit 100, visit Login.aspx will jump to get the cookie page, prompt login id=100, as follows:
Cookies in the manner in which the state is stored in the program