Reputation: 11454
Is it possible to have a cookie expire at the end of a session, or at a specific time?
Upvotes: 4
Views: 7327
Reputation: 11454
since this is not possible with a single cookie i am sending two cookies. the auth cookie expires at the end of the session. the second cookie expires at a specific time. on each request i check the second cookie and if it is null i log the user out manually.
Upvotes: 1
Reputation: 1053
Yep! It's simple
HttpCookie newCookie = new HttpCookie("myCookie");
newCookie.Expires = DateTime.Today.AddDays(1);
If you want the cookie to be for the session, set it to DateTime.MinValue
. See the MSDN Documentation here for more info. Here's the excerpt:
Setting the Expires property to MinValue makes this a session Cookie, which is its default value.
Upvotes: 1
Reputation: 3401
You can control cookie life time with Expires and Max-Age
properties. Anyway if session is expired or you invalidate it impliclty, cookie associated with this session (for example jsessionId) are not valid anymore.
Upvotes: 0