Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i set cookie expire time in C#

How do I set cookie expiration time in C#?

I want cookies to expire when the browser is closed. I found in many blogs that giving a previous date as the expiry date will cause the cookie to automatically expire, but that is not working in my case.


2 Answers

Hii bhasker,

The simple answer for your question is, do not explicitly specify cookie expiry time at the time of creation of a cookie. Then it will expire when the session is completed or the browser is closed.

like image 59
Venkatesh Appala Avatar answered Dec 16 '25 23:12

Venkatesh Appala


You also have to close all other pages from the same browser, for example if you are using firefox, you have a process nameed firefox.exe which will not end until last window is open and session wil not expire

like image 45
Alireza Rinan Avatar answered Dec 16 '25 21:12

Alireza Rinan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!