Asp.Net MVC与 Asp.Net Core MVC 中设置和读取Cookie
Asp.Net 中
控制器中
public ActionResult Index()
{
//设置cookie,键是address值是 乌托邦
Response.Cookies["address"].Value="乌托邦";
}
视图中读取cookie
<h1>@Request.Cookies["address"].Value</h2>
Asp.Net Core 中
控制器中
public ActionResult Index()
{
//设置cookie,键是address值是 乌托邦
Response.Cookies.Append=("address","乌托邦");
}
视图中读取cookie
<h1>@ViewContext.HttpContext.Request.Cookies["address"]</h2>