Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set cookie expiration to "session" in C#?

Self-Explanatory. In PHP, the solution would be to set the cookie expiration to 0; I'm unsure about C# since it requires a DateTime value.

like image 747
Gio Avatar asked Nov 22 '09 23:11

Gio


People also ask

How do I set cookies to expire at end of session?

To set a cookie so it expires at the end of the browsing session, simply OMIT the expiration parameter altogether.

How do you set the expiry date on cookies?

Set an expiration date for a cookie This can be done easily by adding expires=expirationDate in UTC separated by semicolon from the name=value, as seen in the following example: document. cookie = "username=Max Brown; expires=Wed, 05 Aug 2020 23:00:00 UTC"; document.

When using a cookie to store a session when does a session expire?

Session cookies expire once you log off or close the browser. They are only stored temporarily and are destroyed after leaving the page.

Which property is used to set expire date for cookie?

The Kind property of Expires is used to determine if the cookie is set to DateTimeKind.


1 Answers

The docs for Cookie.Expires call it right out.

Setting the Expires property to MinValue makes this a session Cookie, which is its default value.

cookie.Expires = DateTime.MinValue 
like image 125
Michael Petrotta Avatar answered Sep 28 '22 04:09

Michael Petrotta