Session.Timeout in Classic ASP: Set and Check Session Expiry

Session.Timeout sets the number of idle minutes a Classic ASP session can keep its server-side data. If the visitor does not make another request associated with that session before the limit is reached, IIS ends it. It is an inactivity limit, not a countdown from the moment a user signs in.

Quick answer: Session.Timeout = 10 sets a 10-minute inactivity timeout; Response.Write Session.Timeout displays the configured value. The usual IIS Classic ASP default is 20 minutes, but administrators can change it.

Quick example: set and display a 10-minute timeout

<%
Session.Timeout = 10
Response.Write "Session timeout: " & Session.Timeout & " minutes"
%>

Output: Session timeout: 10 minutes. This sets the value for the current session. The next request associated with the active session refreshes the inactivity period.

Session.Timeout syntax

Session.Timeout = minutes
Response.Write Session.Timeout

minutes is the idle-time limit assigned to the current session, expressed as a number of minutes. Unlike Server.ScriptTimeout, which controls a request-processing limit, this property concerns the lifetime of idle session state.

ExpressionWhat it does
Session.Timeout = 10Sets 10 idle minutes for this session.
Session.TimeoutReturns the current timeout value in minutes.
Session.AbandonSchedules the current session for termination after the page finishes.
Session("key")Reads or writes a value stored in session state.

Set the inactivity timeout for the current session

<%
Session.Timeout = 10
%>

Add this statement to the ASP page where you need to configure the session. The value is specific to the session being processed; it does not change the server-wide setting for other users.

Use shorter values for sensitive pages

<%
Session.Timeout = 5
Response.Write "Idle timeout is " & Session.Timeout & " minutes."
%>

Output: Idle timeout is 5 minutes. A short timeout reduces the time session data persists when visitors leave, but users may need to sign in again more often.

Display the current Session.Timeout value

Use the value directly in Response.Write. The following version retains the original tutorial’s two-line message:

<%
Response.Write "Your session will time out after " & _
    Session.Timeout & " minutes"
%>

Output: Your session will time out after 20 minutes when the current value is 20. If it was set to 10, the output displays 10 instead. The underscore is VBScript’s line-continuation character and must be preceded by a space.

Display the current session ID for debugging

<%
Response.Write "Timeout: " & Session.Timeout & " minutes<br>"
Response.Write "Session is active"
%>

Avoid exposing Session.SessionID in a public page: session identifiers are sensitive. A simple test message and session-stored value are usually sufficient for learning and debugging.

When does a Classic ASP session expire?

The inactivity timer is measured from the most recent request associated with the session, not from the first page load. A page that is left open without requests does not, by itself, keep the session alive.

Example timelineWhat happens with a 10-minute timeout?
10:00 AMVisitor loads an ASP page and a session value is created.
10:06 AMVisitor opens another page in the same ASP application; the idle period starts again.
10:12 AMVisitor opens another page; session data is still available because only six minutes passed.
After 10:22 AM with no further requestsThe session becomes eligible for expiry; an exact cleanup instant should not be assumed.
Important: Session.Timeout does not automatically redirect a browser tab or display a countdown. The application discovers expired state when a subsequent request checks for a session value. Automatic refreshes or background requests that participate in the session may extend its lifetime.

Practical example: save and check a session value

Try these two files in the same Classic ASP application on IIS. The first page creates a session value; the second checks whether it is still present.

File 1: start-session.asp

<%@ Language="VBScript" %>
<%
Option Explicit
Session.Timeout = 10
Session("tutorialVisitor") = "Alex"
Response.Write "Saved visitor: " & Server.HTMLEncode(Session("tutorialVisitor"))
%>
<p><a href="check-session.asp">Check the session</a></p>

Output: Saved visitor: Alex. Open check-session.asp before the timeout to see the stored value.

File 2: check-session.asp

<%@ Language="VBScript" %>
<%
Option Explicit
If IsEmpty(Session("tutorialVisitor")) Then
    Response.Write "Session value is missing or has expired."
Else
    Response.Write "Welcome back, " & _
        Server.HTMLEncode(Session("tutorialVisitor"))
End If
%>

On the first visit, the output is Welcome back, Alex. After the session expires, the stored value is no longer available and the page displays the fallback message. A missing value can also occur if the visitor never opened the first page, explicitly logged out, or session state was lost due to a server restart.

Handling an expired session value safely

<%
If IsEmpty(Session("tutorialVisitor")) Then
    Response.Write "Please start the session again."
Else
    Response.Write Server.HTMLEncode(Session("tutorialVisitor"))
End If
%>

Check for an expected session value rather than treating the number returned by Session.Timeout as proof that a visitor is signed in. Learn more about storing values in Session variables.

Check authentication on each protected page

In a real member area, a login handler should set a session flag only after validating credentials on the server. Each protected page must check that authentication state still exists.

<%@ Language="VBScript" %>
<%
Option Explicit
If IsEmpty(Session("isAuthenticated")) Then
    Response.Redirect "login.asp"
ElseIf Session("isAuthenticated") <> True Then
    Response.Redirect "login.asp"
End If
%>
<h1>Member area</h1>
<p>This page is for signed-in users.</p>

Here login.asp is a placeholder for your actual login route, not an extra file supplied with this tutorial. Do not set the flag to True merely because a visitor opened the page. For a complete access-control flow, see checking login sessions and protecting member pages.

Security: expiry is only one control. Use HTTPS, secure cookie configuration, authentication checks for every protected request, and explicit logout. Avoid storing passwords or other highly sensitive secrets directly in session variables.

End a session deliberately with Session.Abandon

Session.Abandon is used when the visitor signs out. IIS disposes of the session state after the current ASP page has finished processing; it is not removed at the exact moment the statement executes.

<%@ Language="VBScript" %>
<%
Option Explicit
Session.Abandon
Response.Write "You have signed out."
%>

Output: You have signed out. The next request should not be trusted as authenticated until it passes the login process again.

Simple sign-out redirect

<%
Session.Abandon
Response.Redirect "login.asp"
%>

Replace login.asp with your actual sign-in URL. If your site also uses authentication cookies or persistent login tokens, handle those in the logout flow too; abandoning the Classic ASP session alone does not revoke every possible credential.

Change the application default in IIS

The configured Classic ASP session timeout is commonly 20 minutes by default. An IIS administrator can change it for the site or application: open IIS Manager, select the application, open ASP, expand Session Properties, edit the timeout setting and apply the changes.

In IIS configuration, the corresponding property is system.webServer/asp/session with a timeout value formatted as hh:mm:ss. That setting differs from the minute value used in ASP code:

<system.webServer>
  <asp>
    <session timeout="00:10:00" />
  </asp>
</system.webServer>

The snippet shows the relevant configuration section. Whether you can set it in an application-level web.config depends on IIS configuration permissions and section locking. An administrator should apply the change at an authorized configuration level.

Microsoft documents the IIS ASP session settings and default timeout. The ASP-specific session start and end behavior is also described in Microsoft’s classic documentation.

Session timeout versus other time limits

SettingControlsUnit or behavior
Session.TimeoutHow long server-side Classic ASP session state may remain idle.Minutes
Server.ScriptTimeoutHow long an ASP request is allowed to execute.Seconds
IIS application pool idle timeoutWhen the worker process may shut down because it is idle.Separately configured; may affect in-memory session state
Authentication cookie or token expiryHow long a login credential remains valid.Controlled by the authentication mechanism
JavaScript idle warningWhat the open browser tab displays to a user.Client-side only; cannot replace server authorization checks

Troubleshooting Session.Timeout

ProblemWhat to check
Session data disappears too soonCheck the effective timeout, app-pool restarts or recycling, session cookies, and whether requests reach the same application.
A visitor stays signed in after waitingCheck for background ASP requests that keep the session active, or a separate authentication cookie that survives session expiry.
The browser does not redirect at 10 minutesTimeout acts on server-side session state. Run authorization checks on requests and implement a separate UI warning if needed.
Session.Timeout still shows the old valueCheck whether the assignment ran for that session and whether an IIS/application setting or another ASP page changes it.
Session value is missing immediatelyMake sure Classic ASP session state is enabled, cookies work, and the value was set before checking it.
Sessions disappear during deploymentIn-process session state can be lost when its hosting worker process restarts or recycles.

Frequently asked questions

What is the default Session.Timeout in Classic ASP?

The standard IIS Classic ASP session configuration uses a 20-minute default. Administrators can change this setting, so the effective value is best checked on your own server.

Is Session.Timeout measured in seconds or minutes?

The Session.Timeout ASP property uses minutes. The IIS configuration attribute uses the hh:mm:ss format.

Does Session.Timeout log a user out automatically?

It expires session data after inactivity. Your application must check authentication state on each protected request and decide whether to show or redirect to a login page.

Can I use Session.Timeout to show a browser countdown?

No. It is a server-side setting. A browser countdown is separate UI behavior, and its estimate can differ from the server if other requests refresh the session.

How do I end the session before the timeout?

Call Session.Abandon, then apply your application’s full logout procedure.

What happens to session variables after expiry?

The previous session data is unavailable. A new session can be created on a later request, but it does not automatically restore the old values.

Is Session.Timeout the same as Server.ScriptTimeout?

No. One concerns idle session state and is expressed in minutes; the other limits request execution and is expressed in seconds.

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer