0

I am using the login control and the login button is in the master page.

I have a page (i.e. page1.aspx) where user can go with login and without login as well.

If the user is in that page1.aspx and clicks the login button, after successful login I want the system to take the user back to page1.aspx.

But now after successful login, system takes the user to the default.aspx page.

How can I achieve this? any help?

0

4 Answers 4

2

FormsAuthentication.RedirectFromLoginPage Method (String, Boolean)

Redirects an authenticated user back to the originally requested URL or the default URL.

1

You need to pass URL as GET parameter to Login Page and after login successful redirect page to URL passed as GET parameter.

For example:

News.aspx:

<a href="Login.aspx?BackTo=News.aspx">Login</a>

Login.aspx:

if (loginSuccess) {
   Response.Redirect(Request.QueryString["BackTo"] ?? "Default.aspx");
}
0

In your login.aspx page when the login is successful you need to redirect the browser using

<% Response.Redirect("page1.aspx", true) %>

if you submit an addition information in the form for which the page the user is currently on you can the use the redirect to put them back on that page.

4
  • well, if I use <% Response.Redirect("page1.aspx", true) %>, it will be return to page1.aspx. But I have some other pages like this (i.e.page2.aspx, page3.aspx). in those cases it will return to always return to page1.aspx. But I dont know from which page user will click the login button. What I want is whichever page the user is in, after successful login, it will redirect user to the page where the user was.
    – Reza.Hoque
    May 11, 2011 at 9:26
  • what i was saying is that if you replace the page1.aspx with the page you to want return them to, sent as a hidden element in the form then it will redirect back to the given page. Sorry if i wasn't clear. May 11, 2011 at 9:33
  • Yes, I understood. But what i can not figure out is the login link is in masterpage. how can i send the current page url to the login page??
    – Reza.Hoque
    May 11, 2011 at 10:00
  • How are you currently doing the login? if you are using a form you could use a hidden element in the form with the value of the page. May 11, 2011 at 10:22
0
<a href="Login.aspx?BackTo=News.aspx?BackTo=<%= Request.RawUrl() %>">Login</a> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.