what is the default expiration time of a cookie
Asked Answered
B

2

48

By default what will be the expiration time of a cookie added using C# code?

    HttpCookie myCookie= new HttpCookie("myCookie");
    myCookie.Value = txtCookie.Text;       
    // Add the cookie.
    Response.Cookies.Add(myCookie);
Bobbe answered 25/9, 2013 at 10:19 Comment(0)
F
47

The default Expires value for a cookie is not a static time, but it creates a Session cookie. This will stay active until the user closes their browser/clears their cookies. You can override this as required.

From the linked page:

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

Forwhy answered 25/9, 2013 at 10:24 Comment(2)
And the session cookie expires in 14 days by default (in Owin), see code here github.com/yreynhout/katana-clone/blob/master/src/…Overlord
It's not specific to C#, right? It's default behaviour in browsers as well? Like when you do document.cookie = 'asd=123' it persists till you close the browser too unless you specified an expiration time?Gargoyle
T
-11

20 minutes.
In IIS, click on your website, and go to Session State. In the second box (Cookie Settings), you can change the time out(in minutes).

enter image description here

Tirade answered 25/9, 2013 at 10:36 Comment(2)
I downvoted this because this is for the Session cookie. This will not affect the timeout in the code shown in the original answer.Forwhy
And this timeout is probably for the server-side session timeout. This has nothing to do with cookie expiry time.Fineable

© 2022 - 2024 — McMap. All rights reserved.