Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a non-persistent (in memory) http cookie in C#?

I want my cookie to disappear when the user closes their brower-- I've already set some promising looking properties, but my cookies pop back to live even after closing the entire browser.

HttpCookie cookie = new HttpCookie("mycookie", "abc");
cookie.HttpOnly = true; //Seems to only affect script access
cookie.Secure = true; //Seems to affect only https transport

What property or method call am I missing to achieve an in memory cookie?

like image 755
MatthewMartin Avatar asked Dec 21 '10 15:12

MatthewMartin


People also ask

Are cookies guaranteed to be persistent?

Some cookies are allocated to your PC only for the duration of your visit to a website, and these are called session based cookies. These automatically expire when you close down your browser. Another type of cookie would remain on your PC for a period of time. These are known as “persistent” cookies.

What is the difference between persistent and non persistent cookies?

Both persistent and session cookies store a user's information, settings, preferences, or sign-on credentials, when the user consents to such information being stored. However, persistent cookies retain this information even after users close their browsers.

Do cookies persist across sessions?

Session cookies do not retain any information on your device or send information from your device. These cookies are deleted when the session expires or is terminated when the browser window is closed. Persistent cookies remain on the device until you erase them or they expire.


1 Answers

cookie.Expires = DateTime.MinValue;

this cookie will expire, as soon as the browser is closed.

like image 106
nothrow Avatar answered Oct 18 '22 04:10

nothrow