How To Read And Write A Cookie In ASP.NET
You can use cookies to store data about your site visitors. Because cookies are just plain text files, they are usually not used to store sensitive data, especially without some kind of encryption.
To create new cookie or save existing cookie, use this code:
[ C# ]
Response.Cookies["CookieName"].Value =
"CookieValue";
// Cookies are temporally files, so you need to set how long cookie will be present on client hard disk before it is deleted
Response.Cookies["CookieName"].Expires = DateTime.Now.AddDays(100);
[ VB.NET ]
Response.Cookies("CookieName").Value =
"CookieValue"
' Cookies are temporally files, so you need to set how long cookie will be present on client hard disk before it is deleted
Response.Cookies("CookieName").Expires =
Now.AddDays(100)
To read cookie, you can use this code:
[ C# ]
// check if cookie exists
if(Request.Cookies["CookieName"]
!= null)
CookieValue = Request.Cookies["CookieName"].Value;
[ VB.NET ]
' Check if cookie exists
If
Not Request.Cookies("CookieName")
Is Nothing
Then
CookieValue =
Request.Cookies("CookieName").Value
End
If
To learn in details about cookies check Cookies In ASP.NET tutorial.
Related articles:
1. Creating a Web Site Preloader In Flash
2. Taskbar Application in .NET
3. What Are Master Pages?