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

Posted on 2009-02-23
Last Modified: 2013-12-17
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

Question by:mugsey
    LVL 39

    Expert Comment

    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

    LVL 39

    Expert Comment

    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

    Author Comment

    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
    LVL 39

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now