The realization remembers the password, the expiration date and so on function. Cookies.
The Expires property and the Value property of the cookie object.
/////////////////////////////////////////////////////////////////////////////////////////////////////
Using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;
public partial class Admin:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (session["username"] = = null)
{
Response.Redirect ("default.aspx");
}
Else
{
Response.Write ("codego.net" + session["username"] + "Successful login! ");
}
}
}
///////////////////////////////////////////////////////////////////////////
Using System;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void button2_click (object sender, EventArgs e)
{
Txtname. Text = "";
Txtpwd. Text = "";
}
protected void Button1_Click (object sender, EventArgs e)
{
if (txtname. Text.trim (). Equals ("Mr") && txtpwd. Text.trim (). Equals ("Mrsoft"))
{
session["username"] = txtname. Text.trim ();
if (Ckbauto. Checked)
{
if (request.cookies["username"] = = null)
{
response.cookies["username"]. Expires = DateTime.Now.AddDays (30);
response.cookies["Userpwd"]. Expires = DateTime.Now.AddDays (30);
response.cookies["username"]. Value = txtname. Text.trim ();
response.cookies["Userpwd"]. Value = Txtpwd. Text.trim ();
}
}
Response.Redirect ("admin.aspx");
}
Else
{
Clientscript.registerstartupscript (this. GetType (), "", "alert (' Username or password error! '); ", true);
}
}
protected void Txtname_textchanged (object sender, EventArgs e)
{
if (request.cookies["username"]! = NULL)
{
if (request.cookies["username"]. Value.equals (txtname. Text.trim ()))
{
Txtpwd. attributes["value"] = request.cookies["Userpwd"]. Value;
}
}
}
}
This article is from the "Zhutousandebokezhijia" blog, make sure to keep this source http://9529231.blog.51cto.com/9519231/1571111
Cache Object Cookie object (ASP. NET technology)