Classic ASP Session ID Cookie Lifetime

asp-classicsession

In my classic ASP application, the ASP session ID related cookie gets lost when the client closes his browser, Even thought the session didn't timeout. So…

How to make ASP session ID cookie to remain the same even if the clients closes his browser?

Best Answer

When you start a new browser session and browse to your site, classic ASP will detect that there is no ASP session cookie and will create a new session for you (as you have already experienced).

Session cookies are just that, they exist for the lifetime of the session. When you close your browser the session cookie will be deleted (even though your session state on the server will live on as an orphaned session until Session.Timeout expires - unless you present the same session cookie again within the Session.Timeout period).

The only way to extend the lifetime of the ASP session cookie across new browser sessions/instances would be to alter the cookie lifetime using script on the browser/client.

If you're looking to manage state across events such as the browser closing, you'll need implement your own state management mechanism (persist state to a database for example) and use a regular cookie with a long lifetime (or with a sliding expiration where you extend the lifetime by a small amount of time on each request in your server side script) to match state to the user.

Edit:

The following article has a script to modify the session cookie (scroll down to Cookie Expiration):

But as Shoban correctly points out there is a risk of Session Fixation (OWASP). You can however go some way to protect yourself against this:

I'd also add some caveats, if your application is storing sensitive data (credit cards, financials, medical etc) then I'd suggest not doing this and live with the fact that your user will have to logon again and start a new session. Better safe than sorry.

Related Topic