「asp.net開発」cookieの書き込み、読み取り操作方法

1.cookieを書き込む
HttpCookie cookie = new HttpCookie(“id_admin_");
cookie.Value = model.id_admin_.ToString();
HttpContext.Current.Response.Cookies.Add(cookie);

cookie = new HttpCookie(“name_admin_");
cookie.Value = HttpUtility.UrlEncode(model.name_admin_);
HttpContext.Current.Response.Cookies.Add(cookie);

cookie = new HttpCookie(“guid");
cookie.Value = Guid.NewGuid().ToString();
HttpContext.Current.Response.Cookies.Add(cookie);

2.cookieを読み取り
HttpContext.Current.Request.Cookies[“guid"].Value

3.cookieをクリア
Response.Cookies[“admin"].Expires = DateTime.Now.AddDays(-1);

VB.net

Posted by arkgame