Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove or Reset Cookies

Tags:

vb.net

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.

like image 923
Mithil Avatar asked Dec 22 '08 21:12

Mithil


People also ask

What happens when you reset your cookies?

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.

Should you reset cookies?

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.

Is it OK to remove all cookies from my computer?

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.

What happens if you get rid of all your cookies?

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.


1 Answers

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

like image 85
cgreeno Avatar answered Nov 15 '22 08:11

cgreeno