How to set cookie expiration time in C #

How to set cookie expiration time in C #?

I want cookies to expire when the browser is closed. On many blogs, I have found that dating a previous date as an expiration date will cause the cookie to automatically expire, but this does not work in my case.

+3
source share
5 answers

Hii bhasker,

The simple answer to your question is that I do not explicitly indicate the expiration time of the cookie when the cookie was created. Then it will expire after the session ends or the browser closes.

+4
source

cookie? , , , cookie.

+1

, , firefox, firefox.exe, , .

+1
var cookie = new HttpCookie("name", "value")
{
    HttpOnly = true
};

Expires, cookie.

0

cookie, "" .

Let's say the browser stores a cookie that expires tomorrow. When you change the cookie expiration date to yesterday, the browser sniffs it and says, “This has expired, I'm going to toss it”, effectively deleting the cookie (there really is no other way to delete the cookie).

If you do not set an expiration time when the cookie is created and you do not edit this property, the cookie automatically becomes a session cookie, as a result of which the cookie is deleted when the user closes the browser.

0
source

Source: https://habr.com/ru/post/1788134/


All Articles