[HttpPost]
public ActionResult Login()
{
//写入cookies方式1
HttpCookie cookie = new HttpCookie("tempToken");
cookie.Value = "123456";
cookie.Expires = DateTime.Now.AddDays(7);
Response.Cookies.Add(cookie);
//写入cookies方式2
Response.Cookies["tempToken"].Value = "123456";
Response.Cookies["tempToken"].Expires = DateTime.Now.AddDays(7);
return Json(new { message="cookie设置成功"});
}
[HttpPost]
public ActionResult GainCookie()
{
//读取cookies
string cook="";
if (Request.Cookies["tempToken"]!=null)
{
cook = Request.Cookies["tempToken"].Value;
}
return Json(new { message=cook});
}
[HttpPost]
public ActionResult ClearCookie()
{
//清除cookies
Response.Cookies["tempToken"].Expires = DateTime.Now.AddDays(-1);
return Json(new { message="清除成功"});
}