views:

844

answers:

5

I am maintaining a session for user login.

Consider a scenario that, User working on page20 with his account credential. He is idle for the session variable time out. Then he start working on page20 and click link of page21.Here session is expired so he'll redirect to Login page.

After successful logged in, User should redirect to the page21.

So how do I achieve it?

+2  A: 

The first method that comes to mind is to send the information through a get/post-variable. When you perform the session-check at page21 (I assume) and redirect the user to the login page, you can append the pagename to the address, i.e. redirect to something like www.xyz.com/login.htm?page21 (or if you don't want the pagename to be visible, use post instead). Then simply use that information when the user logs in again to redirect him/her to page21.

Hope that helps.

aspartame
A: 

If you are doing a Server.Transfer to the login page than Request.Urlreferrer would be URL of the Page21.

FutureGuy
+2  A: 

if you are using forms authentication, there is an inbuilt mechanism to do that, here it is. It will automatically redirect the user to the URL Referrer page

If (FrameworkManager.Authenticate(username, pwd)) Then        
   System.Web.Security.FormsAuthentication.RedirectFromLoginPage(username, rememberme)
end if
Vikram
NOTE: FrameworkManager.Authenticate is our internal library. I just put that for simple demonstration of authentication condition being true.
Vikram
+1  A: 

Really it depends on how you're using your session. If you're keeping all of the information the user enters on screens 1-20 in session, you're going to lose it all once their session expires, so you're out of luck anyway.

If you're storing everything from each page in a database, or some other mechanism, then it should be easy to tell what the last piece of information the user entered. Alternatively, you could also store the url or name of the last page the user submitted in the database.

When they log in, determine which page they should be on, then just redirect them.

AaronS
A: 

Where would you put this code?

If (FrameworkManager.Authenticate(username, pwd)) Then
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(username, rememberme) end if

Tony Borf