I am setting a cookie Request.Cookies("TemplateName").value
on one of my pages(page 3) of my application. Now I can navigate from page 3 to page 4 and page 2 and retain the value of the cookie. But now when I logout and login again it still has the value, how can I reset the value of the cookie to be blank "" when I start a new instance?
I tried:
Request.Cookies("TemplateName").Expires = Now
Request.Cookies("TemplateName").value = ""
On my homepage, but the cookie still retains the value on page 2 and 3.
What happens when you remove all cookies? Deleting cookies wipes all your personal information from your browser, including usernames, passwords, search history, and website settings and preferences.
So how often should you clean these cookies? If you're using a public computer, you should delete them and other data, such as browsing history, right after your session. If it's your personal device, it's a good idea to remove all cookies at least once a month to keep your device neat.
Click See All Cookies and Site Data to see a list of the cookies actually installed locally on your computer. You can go through them one by one and delete as desired. It's not a bad idea to just do a Remove All on cookies every few months, just to clear things out.
Clear all cookies If you remove cookies, you'll be signed out of websites and your saved preferences could be deleted. Settings. Clear browsing data. Choose a time range, like Last hour or All time.
You need to use the Response not the Request
Response.Cookies["TemplateName"].Value = "";
Response.Cookies["TemplateName"].Expires = DateTime.Now;
EDIT For VB.
Dim subkeyName As String
subkeyName = "userName"
Dim aCookie As HttpCookie = Request.Cookies("userInfo")
aCookie.Values.Remove(subkeyName)
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)
Response.Cookies("userName").Value = "patrick"
Response.Cookies("userName").Expires = DateTime.Now.AddDays(1)
These Examples come right off the MSDN site
SideNote
Often people attempt to use
Request.Cookies.Remove("MyCookie");
Which will only remove the cookie from the "request collection", If you want to remove a cookie then you need to expire it. More info here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With