1

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?

KiKMak
  • 828
  • 7
  • 27
Vikas
  • 24,082
  • 37
  • 117
  • 159

6 Answers6

2

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
  • 4,622
  • 7
  • 36
  • 39
2

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
  • 6,865
  • 9
  • 50
  • 61
  • NOTE: FrameworkManager.Authenticate is our internal library. I just put that for simple demonstration of authentication condition being true. – Vikram May 11 '09 at 06:03
1

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
  • 7,649
  • 5
  • 30
  • 56
0

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

FutureGuy
  • 61
  • 6
0

Where would you put this code?

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

Tony Borf
  • 4,579
  • 8
  • 43
  • 51
-1

If user wants to login again through another browser then in this situation you must add status column in your database and check if the status is true then you have to redirect this user on last visited page.So save the visited page through cookies and get back page name and redirect on the page.

  • The question was about the session expiring, not about logging in in a different browser. I'm confused, what are you recommending? That a boolean status column be added to a database? What does `true` represent here? Does it get updated every time the user does something? How do you know how when the session expires? If your redirect to the last visited page should work by setting and updating a cookie every time the user navigates to another page, why not save that to the DB as well? – Amos M. Carpenter May 01 '15 at 07:29