Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear cookies on browser close

How to clear the cookies that has been stored through my asp.net mvc(C#) application, when the user closes the browser?

Is there any option to create a cookie such that it expires once the browser closed?

I need to use cookies, because i will store some of the values to be maintained until the browser is closed.

For example, During sign in i may store the userid in cookie, which i can use for my application processes till the bwoser closes.

Session will expire after some particular time, which i need to overcome with using cookies

like image 801
Prasad Avatar asked Nov 23 '09 14:11

Prasad


People also ask

Are cookies cleared when browser close?

@JacobRossDev Closing the browser tab will not clear the session cookie, it will only be cleared when browser is closed.

How do I clear cookies on closed tab?

The solution is to delete the cookie from the server, which will require an HTTP request before the tab is closed. Most JS libraries will use asynchronous HTTP requests, which will cause the tab to be closed before receiving the expired cookie from the server, so asynchronous calls will not work reliably.

Can I set Chrome to clear cache on exit?

Scroll down to find Advanced and expand that selection. Under Privacy and Security, choose button for Content Settings. Click the button to Clear Cookies and Site Data when you quit Chrome.


1 Answers

Sessions are usualy used for this. According to Wikipedia, when no expiration date is set, a cookie is cleared when the user closes the browser.

The cookie setter can specify a deletion date, in which case the cookie will be removed on that date. If the cookie setter does not specify a date, the cookie is removed once the user quits his or her browser.

like image 83
Ikke Avatar answered Sep 30 '22 07:09

Ikke