Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2004, 08:18 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default Session Expired Redirect

Hi

I have got a login page that sets a session variable (AUTH=True) after a user has been logged in sucessfully and the redirects them to Default.asp. This asp page is included on all pages that I need to secure. If the session has timed out (+-20min) the user is redirected again to the login page. How do I get them to login again and redirect them to the URL they were comming from instead of the defualt page?

Any ideas.

Regards
Marnus
 
Old July 19th, 2004, 02:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

How are you redirecting? If you are redirecting from session_end, how about tracking the last page (server variable HTTP_Referer) in it (through session or querystring) and store that and redirect based on that.

Brian
 
Old July 19th, 2004, 03:30 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Hi

At the moment when the session automaticly ends as per IIS default it clears the "AUTH=True" session variable I create uppon login. So if the session expires by default, the include file redirects the user back to login.asp Because AUTH is no longer = True (on refresh or next click)

I am not using any methods with sessions to do this. I assume if I use the HTTP_Referer server variable on everypage I need to get it before the session is cleared as this value would also be cleared once the session has died.

Then I assume i need to keep this client side and cary some URL string variable accross pages...Would this be the correct way of thinking? Or would I be able to get the "last URL" variable once the session has expired?

Thanks for your reply. I appreciate anymore sugestions.

Regards
Marnus
 
Old July 19th, 2004, 09:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am not sure if one can redirect using Session_onEnd, though it can be done, for some reason it doesn't work for me, I haven't played around it enough.

Any page you navigate to, the Server variable - HTTP_REFERER will have the URL of previous page(you came from) as its value. Though you abandon your session, these are still available.

Once the session timed out and the user is redirected to the login page, how do you notify the user that the session timed out? I assume you pass some querystring that you request on login page and based on that you show a message saying "Session expired, re-login." If so...

Then follow this way.
Code:
If Request.Querystring("Timedout")="yes" then URL=Request.ServerVariables("HTTP_REFERER")
...
...
<input type=hidden name="URL" value="<%=URL%>">
On the login page store the URL of previous page in a hidden field and once the user logs in, request for form variable URL on the page where it gets submitted and if URL not empty, redirect to that value, else land him on the default page after login.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old January 11th, 2006, 03:51 AM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi acdsky

I am having problem in redirecting page to login page when the session is expired can you please explain me with code that how you redirected to the login page when session got expired. Your help is greatly appreciated. Thank you

Mallik
 
Old January 11th, 2006, 06:26 PM
Registered User
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HTTP_REFERER is not always safe to use, as not all browsers send this variable. My suggestion is to put the following code in your login-check include file:
----
strRedirect = Request.ServerVariables("URL") & "?" & Request.QueryString
Response.Redirect "/login.asp?redirect=" & Server.URLEncode(strRedirect)
----

And in your login file:
----
strRedirect = Request("redirect")
If strRedirect = "" Then strRedirect = "/default.asp?auth=true"
' Login goes here
Response.Redirect strRedirect
----

Lasse

 
Old January 11th, 2006, 07:07 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

There are many ways to skin a cat, here is a simple but effective way.

1..When your user logs in set a session variable, EG:
session("loggedIn") = "y"

2..Then in the head of every page you would like to detect 'are they logged in' place
<%
  if session("loggedIn") <> "y" then
     response.redirect("loginPageName.asp?ses=exp")
  end if
%>

Now further down the page you may wish to show a warning, EG:

<%
   if trim(request.querystring("ses") = "exp" then
      response.write "Your session has expired, you are required to log into the ayatem again"
   end if
%>

This also prevents people from saving a page to thier favourites after logging in and trying to hit the page without logging in again. The only way to set the session variable session("loggedIn") to "y" is to log in.

Wind is your friend
Matt
 
Old August 28th, 2006, 03:24 AM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mat41 if U do it that way and if user wishes to remain anonymous i.e. to view free content it will always get the exp_ses message ... maybe this is not the right way or U R missing something important !

I have similar problem. I am trying to detect expired session so I can display error message. I tried several method but none successfull.





Similar Threads
Thread Thread Starter Forum Replies Last Post
redirect querystring with session value alxtech Classic ASP Professional 1 July 16th, 2007 07:06 AM
error:(session expired) hara_sap Servlets 0 March 18th, 2005 05:54 AM
Session gets null on Response.Redirect Baby_programmer ASP.NET 1.x and 2.0 Application Design 2 March 11th, 2005 12:38 AM
Session Gets null on Response.Redirect Baby_programmer ASP.NET 1.0 and 1.1 Basics 1 March 8th, 2005 03:30 PM
Expired CR9 session kills IIS darkov Crystal Reports 0 March 15th, 2004 05:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.