• 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

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

  • 3
1 Solution
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
End Sub

Open in new window

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
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
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.

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