![]() |
Setting A Cookie in ASP.NET
What Is A CookieA cookie is a small text file sent to a web user's computer by a website. A cookie can be used to identify that user to the website on their next visit. Common uses include remembering login data, user preferences, and providing favorites lists. How Does A Cookie WorkHTTP cookies are used by Web servers to differentiate users and to maintain data related to the user during navigation, possibly across multiple visits. When an user visits/logs in to go4expert.com the web server sets a cookie to track the user's last visted time, and some ID to track the specific visitor. Many websites also use cookies for personalization based on users' preferences. How Much Can We Store In A CookieCookie specifications suggest that browsers should support a minimal number of cookies or amount of memory for storing them. In particular, an internet browser is expected to be able to store at least 300 cookies of four kilobytes each (both name and value count towards this 4 kilobyte limit), and at least 20 cookies per server or domain, so it is not a good idea to use a different cookie for each variable that has to be saved. It's better to save all needed data into one single cookie. Setting A Cookie in ASP.NetSetting cookies with a ASP.Net script is easy, we just need to use the HttpCookie class in the System.Web namespace. Let's look at an example on creating a cookie with ASP.Net Code: C#
Referenceshttp://www.joedolson.com/glossary.php http://en.wikipedia.org/wiki/HTTP_cookie |
Re: Setting A Cookie in ASP.NET
Excellent and very clear article - The only thing which I would add is that by default cookies are only sent for the domain which created them
Therefore if the cookie was written by test.go4expert.com it could not be read by forums.go4expert.comThe way of fixing this is to set the domain of the cookie to the base domain, then both forums.go4expert.com and test.go4expert.com could access the information The code to add would be :- Code:
Response.Cookies("domain").Value = DateTime.Now.ToString() |
Re: Setting A Cookie in ASP.NET
Very nice artical..thanks
|
| All times are GMT +5.5. The time now is 02:21. |