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 Expired. Force User to Log On again 1

Status
Not open for further replies.

Creeder

Programmer
Jul 5, 2000
110
MY
Hi All,

I have the following problem with a few ASP pages. Upon loging on, a new session variable is created. Let's say the user access certain pages and then leave it idle for more than 20 minutes (or more than the session.timeout property).

The user than reaccess the web page and i would like to redirect the user to another page, ie, the login page because the session has timeout. What would be the best approach to do this? Do i have an Include file that has a code in all of the web page that checks whether the session variable has been destroyed and then redirect the user to that page or is there another method?

Thanks for any advice.

 
That's the method that I use. When a user successfully logs into my application, I create a Session Variable like this.


Session("userid") = userid


That happens to be a session variable that I use throughout the application.

In my general.inc include file, which is inserted into every ASP page, I have the following code.


IF Session("userid") = "" THEN
Response.Redirect "login.asp?expired=yes"
END IF


Then on my login page I have a little chunk of code like this.


IF Request.QueryString("expired") = "yes" THEN
'Show a message telling the user that the session has expired.
END IF


You can do it a little differently. I've seen developers redirect expired sessions to a page that explains the session timeout with a link back to the login page. Whatever suits you the best should work.

Remember, you'll need <% Response.Buffer = True %> on any page that you want to issue a Response.Redirect on.

Hope this helps :)

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top