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
@JacobRossDev Closing the browser tab will not clear the session cookie, it will only be cleared when browser is closed.
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.
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.
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.
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