Cookie management in ASP.NET MVC

后端 未结 2 983
北海茫月
北海茫月 2021-01-13 12:05

I want to add some stuff to cookie in ASP.net MVC.

What is best way to handle all stuff in a cookie or more cookie.

Any good way to handle cookie in asp.net

相关标签:
2条回答
  • 2021-01-13 12:31

    I found this one, may be helpful

    http://stephenwalther.com/blog/archive/2008/07/08/asp-net-mvc-tip-15-pass-browser-cookies-and-server-variables-as-action-parameters.aspx

    0 讨论(0)
  • 2021-01-13 12:34

    Here's an example:

    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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题