在ASP.NET MVC中更新多值cookie?

时间:2010-07-19 06:53:52

标签: c# asp.net asp.net-mvc

如何更新ASP.NET中的多值cookie?

1 个答案:

答案 0 :(得分:11)

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