Cookieの使用と有効期間の設定
591 ワード
protected void Page_Load(object sender, EventArgs e)
{
// Cookies
HttpCookie cookie = new HttpCookie("UserName","ZhangSan");
this.Request.Cookies.Add(cookie);
// Cookies
DateTime time = DateTime.Now;
TimeSpan span = new TimeSpan(0, 0, 15, 0, 0);//
cookie.Expires = time.Add(span);// 15
// Cookies
string userName = this.Request.Cookies[0].Value;
this.Response.Write(userName);
// Cookies
this.Response.SetCookie(cookie);
}