General site landing will automatically save a few days of check box, below us. NET environment to realize the preservation of the account and automatic landing.
We need to use the HttpCookie class here.
<summary>
///processing cookies
///</summary>
///<param name= "name" ></param>
<param name= ' pass ' ></param>
///<returns></returns> public
HttpCookie Httpsavecookie (string name, String pass)
{
HttpCookie HTC = new HttpCookie ("Userlogin");
Htc. Values.add ("username", name);
Htc. Values.add ("Userpass", pass);
Htc. Expires = DateTime.Now.AddDays ();
return HTC;
}
When you need to save your account, you should add it before the login code:
Whether to save cookies
if (checkbox2.checked)
Response.Cookies.Add (Httpsavecookie (strname, Strpass));
Where strname and Strpass is the user's account name and password, it is important to note that, for the sake of security, the saved password must be ciphertext, and automatically logon when the time will not be encrypted to judge.
To achieve automatic login, when loading the login page to determine whether there is a cookie, some words directly to get the data to judge, success is logged in.
Implementation code:
if (request.cookies["userlogin"]!= null)
{
HttpCookie HTC = request.cookies["Userlogin"];
String getname = HTC. values["username"]. ToString ();
String getpass = HTC. values["Userpass"]. ToString ();
BOOL data = Sprocedure.userlogin (GetName, getpass);
//......
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/