Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Timeout

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How do you use the session.timout function so that you can logout a user if he/she has not done any action to the page after a certain amount of time.
thanx
 
session.timeout is a properties of the session object. Default value is 20 minutes. The page will aumatically clear the session when the user has not done any action to the page after a certain amount of time.

You can set the session.timeout on top of the asp page or global.asa.
------------------
Freedom is a Right
 
You can declare the default session-timeout time in the code as goatstudio has said, or you can set the default time for the entire site (vs. just one page) in your IIS program under the properties of the web site you are working with, click the "home directory" tab, click the "configuration" button near the bottom on the right side, then in the new dialog box click the "App Options" tab, check the Enable Session State if it's not already checked, and set the minutes in the text-box to your desired time you want the session to last without activity. This will reset the default time for the entire site. -Ovatvvon :-Q
 
In code, you would declare your session object's timeout property in a scriptblock:

<%
Session.Timeout = 30
%>

You could call this value to display is by using:
<html><body>
The timeout limitation for this page is
<%
Response.Write(Session.Timeout)
%>
minutes.
</body></html>

More on this at:
HTH,
Jason
 
ok I think i may have worded my question wrong. what I want to know is How can I check if a user has timedout so that i can send the user back to the logon page and give him/her the correct error message. In other words, my logon page can has a few error checks. It checks for incorrect username, it checks for incorrect password, it checks, or returns an error message when a user types in the url of a specific page without first loging in, and it also should check and return a proper error message when the user has not done any activity on the page (session timeout).

thanx

Please excuse me if I'm being annoying
 
Oh, that's simple...
When the user logs in, set a session variable to true and check for it at the top of every page. If it's not true, then redirect them back to the login page. When the session times out, the session variable will no longer be valid...

login.asp
-----------

<%
If request.form(&quot;userID&quot;) = rs(&quot;uID&quot;) And request.form(&quot;userPW&quot;) = rs(&quot;uPW&quot;) Then
session(&quot;memberFlag&quot;) = true
response.redirect(&quot;intoMemberArea.asp&quot;)
Else
response.redirect(&quot;backToLoginPage.asp&quot;)
End If
%>



intoMemberarea.asp
----------------------------

<%
Dim error
error = Server.URLEncode(&quot;You have to log in again&quot;)
If session(&quot;memberFlag&quot;) <> true Then
response.redirect(&quot;backToLoginPage.asp?error=&quot; & error & &quot;&quot;)
End If

' continue on with normal page for members
%>


You can also just make that check it's own page and include it at the top of every page you in your member area instead of having to retype it on every page.

Hope this helps... -Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top