Redirect from login page to Recover password?

Asked

Viewed 53 times

0

I’m doing an app on ASP . net where I’m logging in with controllers. However on the login page when I click on the hyperlink to do password Recover the control does not leave the login page and I am not redirected to the password Recover page. If I see the URL it changes the url to recoverpassword.aspx but the Recover page does not appear and does not leave the login page.
Can someone help me understand why? Thank you.

Code on the page default.aspx:

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.User.Identity.IsAuthenticated)
        {
            FormsAuthentication.RedirectToLoginPage();
        }
        else if (this.Page.User.IsInRole("Saba") || this.Page.User.IsInRole("CorpAdmin") )
        {
            //Server.Transfer("Report/ListSabaReports.aspx", true);
            Response.Redirect("~/Report/ListSabaReports.aspx");
        }
        else if (this.Page.User.IsInRole("SumTotal"))
        {
            //Server.Transfer("Report/ListSumTotalReports.aspx", true);
            Response.Redirect("~/Report/ListSumTotalReports.aspx");
        }
        else if (this.Page.User.IsInRole("X-Domain"))
        {
            //Server.Transfer("Report/ListSabaReports.aspx", true);
            Response.Redirect("~/Report/ListSabaReports.aspx");
        }
    }
}

Code on the web config:

<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
  <controls>
    <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
      assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </controls>
</pages>

I wish it was that when the login page appeared I have there a hyperlink with the text recoverpassword and I wanted to be redirected to that page but I can’t always get it on the login page. SOMEONE HELPS ME?

  • Could you post part of your controller where you do this login part so we can look at it? It would make your question a lot easier.

1 answer

1

The causes can be several:

If a controller or method is decorated with the authorization annotation [Authorize]the system redirects to the login page.

I would put a breakpoint on the controller and do the debug to realize which code runs.

Edit:

if (!this.Page.User.Identity.IsAuthenticated)
    {
        FormsAuthentication.RedirectToLoginPage();
    }

The above code says that if the user is not authenticated he is redirected to the login page.

Usually the password retrieval link is available to users who nay have logged in, because if they did, they would use the change password option, right?

or if the user click on recover password is not yet authenticated the above code is executed and is always redirected to the login page!

  • and what you would change to be redirected to the password Recover page?

  • As the code is, the user must be authenticated to be able to exit the login page. Remove this code. In the application where you want to force authorization puts [Authorize] with date Annotations.

  • and Authorize also works to redirecttologin()? or is less secure?

  • Yes, In the classes and/or methods decorated with Authorize the system will redirect to the login page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.