Hi!
In ASP.NET MVC, how can I create a single cookie and save multplie values to it?
Thanks!!
Hi!
In ASP.NET MVC, how can I create a single cookie and save multplie values to it?
Thanks!!
var cookie = new HttpCookie();
cookie.Values["FirstKey"] = value1;
cookie.Values["SecondKey"] = value2;
or a shortcut:
cookie["ThirdKey"] = value3;
HttpCookie.Values is a NameValueCollection, a class that appears in many places in ASP.NET MVC. Read this for a good tutorial on how to use it to its full potential.
This problem can be rephrased as: "How can I store multiple values in a single string?"
It's up to you to come up with a system. If the values are simples numbers or strings, use a separator like a ";" and then split later.