Cookies with Multiple Values in ASP.NET

Recently we discussed various facts about a Cookie. Today we will see that how a single cookie can store multiple values. First we will create a Cookie then we will store multiple values in the same Cookie. Also the important thing is to retrieve the all values of that cookies. Whether you can retrieve the values in the same variable of multiple variables.




Creating Cookie with Multiple Values:

Response.Cookies["empCookie"]["name"]= txtName.Text;
Response.Cookies["empCookie"]["age"]= txtAge.Text;
Response.Cookies["empCookie"]["Location"]= txtLocation.Text;

Retrieving multiple Cookies Value in single Variable:

We are going to Fetch the value in a single variable with comma(,) seperated value.

 string empdetails;
 empdetails = Request.Cookies["empCookie"]["name"]+","+Request.Cookies["empCookie"]["Age"]+","+Request.Cookies["empCookies"]["Location"];

Author Bio : This is Rajendra, A blogger running with a tech blog Daily Tech Updates .

Suggested Entry:
Cookies in ASP.NET
passing Multiple Values in QueryString

admin (158 Posts)


Leave a reply

Your email address will not be published.

Comment moderation is enabled. Your comment may take some time to appear.