DELETE me
DELETE me

Reputation:

Updating a multi value cookie in ASP.NET MVC?

How can I update a multi-value cookie in ASP.NET?

Upvotes: 3

Views: 6554

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

public ActionResult ModifyCookie()
{
    // Read the cookie from the request
    var cookie = Request.Cookies["cookieName"];

    // Verify that the cookie was present
    if (cookie != null)
    {
        // modify a value given the key
        cookie.Values["key"] = "modified value";

        // write the modified cookie back to the response
        Response.AppendCookie(cookie);
    }
    return View();
}

Upvotes: 12

Related Questions