HOW TO CREATE MULTIPLE COOKIES IN MVC4?

Ganesh Kumar

Total Post:3

Points:21
Posted by  Ganesh Kumar
Mvc4 
 1642  View(s)
Ratings:
Rate this:
How to create new cookie if the cookie is already create for same application?

Scenario: I have fetched the data and stored into session then cookie has created with session id.
second time i want to maintain different data in another cookie is it possible in mvc4?
  1. Pawan Shukla

    Post:38

    Points:274
    Re: How to create multiple cookies in mvc4?

    Hi Ganesh


    To write and read a single cookie with multiple key/values, it would look something like this:
    HttpCookie cookie = new HttpCookie("mybigcookie");
    cookie.Values.Add("name", name);
    cookie.Values.Add("address", address);

    //get the values out
    string name = Request.Cookies["mybigcookie"]["name"];
    string address = Request.Cookies["mybigcookie"]["address"];

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!