设置Cookie
private void setCookie(string key, string value)
{
var cookie = new HttpCookie(key, value)
{
Expires = DateTime.Now.AddMonths(2);
};
Response.Cookies.Add(cookie);
}
获取Cookie
private string getCookie(string key)
{
var cookie = Request.Cookies[key];
if (cookie != null)
{
return cookie.Value;
}
return null;
}
清除Cookie
public ActionResult Clear()
{
clearCookie();
return Redirect(Request.UrlReferrer.ToString());
}