DELETE me
DELETE me

Reputation:

Cookie management in ASP.NET MVC

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 mvc?

Upvotes: 5

Views: 12471

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

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();
    }
}

Upvotes: 18

Related Questions