• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 722
  • Last Modified:

forms authentication returnurl reverts to login page path when incorrect username or password entered

I have a login  page that works OK using forms authentication with standard membership provider however if you enter incorrect username or password the return url
   
           Request.QueryString["RETURNURL"]

reverts to "login.aspx" so if you then enter correct credentials it will log you in but redirect back to the login page.

How can I solve this problem


0
mugsey
Asked:
mugsey
  • 3
1 Solution
 
abelCommented:
You can add/change the event of LoggedIn to redirect to a page you want. This event is raised after a successful login.





Private Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
        Response.Redirect("~/otherpage.aspx")
End Sub

Open in new window

0
 
abelCommented:
In the event you want to redirect to the page the user last was, you can use the following workaround. In the Page_Load , you can do this:

if Session("last_visited_url") is nothing then
   Session("last_visited_url") = Request.UrlReferer.AbsoluteUri
end if

In the LoggedIn event you can do this:

Session("last_visited_url") = nothing
Response.Redirect(Session("last_visited_url"))
0
 
mugseyAuthor Commented:
HI Thanks

Why does not redirectfromloginpage work??  

I cannot hardcode the "response.redirect" because the one login form is used for two applications.  

So once logged in I want something like

          Formsauthentication.redirectfromloginpage (..........

I have tried this but it still reverts to the login.aspx if you enter incorrect username or password
0
 
abelCommented:
This is, unfortunately the behavior of the login control and you cannot easily change that. The workaround I showed you (with the Session) is the easiest way out of this without having to hardcode the return page.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now