Home > DeveloperSection > Forums > How to create multiple cookies in mvc4?
Ganesh Kumar
Ganesh Kumar

Total Post:3

Posted on    September-09-2015 3:37 AM

 .NET Mvc4 

 1 Reply(s)
 927  View(s)
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?

Pawan Shukla

Total Post:37

Posted on    September-09-2015 11:27 PM

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"];

Don't want to miss updates? Please click the below button!

Follow MindStick