ASP.NET MVC中的Cookie管理

4 cookies asp.net-mvc

我想在ASP.net MVC中添加一些东西给cookie.

什么是处理cookie或更多cookie中所有内容的最佳方法.

在asp.net mvc中处理cookie的任何好方法?

Dar*_*rov 17

这是一个例子:

public class HomeController : Controller
{
    public ActionResult CreateCookie()
    {
        var cookie = new HttpCookie("cookie_name", "some value");
        Response.AppendCookie(cookie);
        return View();
    }

    public ActionResult ReadCookie()
    {
        var cookie = Request.Cookies["cookie_name"];
        if (cookie != null)
        {
            string value = cookie.Value;
        }
        return View();
    }
}
Run Code Online (Sandbox Code Playgroud)