Default.aspx.cs代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Request.Cookies["userInfo"] != null)
{
this.Label1.Text = Request.Cookies["userInfo"]["userName"];
this.Label2.Text = Request.Cookies["userInfo"]["lastVist"];
}
HttpCookie aCookie;
for (int i = 0; i < Request.Cookies.Count; i++)
{
aCookie = Request.Cookies[i];
this.Label3.Text = string.Format("Cookie 名称={0}
Cookie 值={1}", aCookie.Name, aCookie.Value);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string strPwd = TextBox1.Text;
Response.Cookies["strPwd"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(strPwd, "md5");
Response.Write(Response.Cookies["strPwd"].Value.ToString());
}
protected void Button3_Click(object sender, EventArgs e)
{
HttpCookie makecookie = new HttpCookie("Cookie");
makecookie.Value = this.TextBox2.Text;
Response.Cookies.Add(makecookie);
}
protected void Button4_Click(object sender, EventArgs e)
{
HttpCookie readcookie = Request.Cookies["cookie"];
this.TextBox3.Text = readcookie.Value;
}
}