Storing and Retrieving Multiple Values in Cookies - ASP TANMOY

Latest

Thursday 27 August 2015

Storing and Retrieving Multiple Values in Cookies

What is cookie?

Cookies are usually small text files, information that are stored on your computer's browser directory or program data subfolders. Cookies are created when you use your browser to visit a website that uses cookies to keep track of your movements within the site, help you resume where you left off, remember your registered login, theme selection, preferences, and other customization functions. The website stores a corresponding file to the one they set in your browser and in this file they can track and keep information on your movements within the site and any information you may have voluntarily given while visiting the website, such as email address.Cookies are often indispensable for websites that have huge databases, need logins, have customizable themes, other advanced features.


How to store cookie in asp.net with C#?


Write the code bellow to you aspx.cs page. When users login your website this cookie will store your browser. You can customize the code based on your need.


Code:

HttpCookie cookie = new HttpCookie("mybigcookie");
cookie.Values.Add("name", "Tanmoy Barman");
cookie.Values.Add("address", "New Delhi,India");
Response.Cookies.Add(cookie);

How to retrieve cookie from your browser?


It is very simple. Just follow the bellow code. You can use this code based on your need.


Code:

string name = Request.Cookies["mybigcookie"]["name"];
string address = Request.Cookies["mybigcookie"]["address"];

No comments:

Post a Comment