cookies的簡單讀寫方法
阿新 • • 發佈:2017-09-20
cookie
一、cookie的寫入
//定義COOKIES,實例化HttpCookie類並添加值
HttpCookie cookie = new HttpCookie(key, value);
//設置保存時間
cookie.Expires = DateTime.Now.AddDays(1);
//添加當前實例化的cookie
Response.Cookies.Add(cookie);
二、cookie的讀取
public static string GetOwner()
{
if (HttpContext.Current.Request.Cookies[key] == null)
{
throw new Exception("您沒有登錄系統或會話已過期,請重新登錄");
}
else
{
//得到用戶數據
HttpCookie cook = HttpContext.Current.Request.Cookies[key];
return HttpUtility.UrlDecode(cook.Value);
}
}
本文出自 “cookies讀寫” 博客,請務必保留此出處http://13338904.blog.51cto.com/13328904/1967143
cookies的簡單讀寫方法