Redirecting a user back to their last page

T

TG

Hi, I have a question concerning redirecting users who have logged in
using our login page. Once they have properly filled out the form
they should be redirected back to the last page they were viewing. Is
there a way to do this in ASP.NET/VB.NET?

Thanks
TG
 
J

Joerg Jooss

TG said:
Hi, I have a question concerning redirecting users who have logged in
using our login page. Once they have properly filled out the form
they should be redirected back to the last page they were viewing. Is
there a way to do this in ASP.NET/VB.NET?

That's basically how Form Authentication in ASP.NET works. You request some
page foo.aspx, you're redirected to a login page, and after successful
authentication you're being redirected back to foo.aspx.

Cheers,
 
T

Terry Graham

Actually I cannot use Forms Authentication at this point in the site so
I just need a simple way to redirect the user back to their last page
after they have filled out the login information. Can this be done?

Thanks
 
K

Ken Dopierala Jr.

Hi,

This could be either easy or tough depending on how users are getting to
your login page. Are they clicking a button or clicking a link? If they
are clicking a button that causes a postback and then you redirect this will
be easy. Just create a quick session variable and put in the page that
performed the redirect before you redirect. Then from your login just
assign that Session variable to a string, set that Session variable to
Nothing, and redirect them back. If you are using a hyperlink then I'm not
sure how you would do it. Maybe do a search on Environment variables that
IIS holds, maybe one of those holds the page they came from. Other than
that you'd have to hand code it. Or create a class that inherits
System.Web.UI.Page, add code to the Page_Load of that base class to store
the current page in the session, and then inherit that page whereever you
have a link to the login page. Don't inherit the login page from this.
Good luck! Ken.
 
N

Nick Malik

Hi Ken,

When a user clicks a link from one page to the next, the HTTP_REFERER header
gets the URL of the referring page. The original poster can easily use that
value to reference where to go back to.

-- Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top