Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing login page for my asp.net application. I am using Formsauthentication class. Login page consist of login button and forgot password link button. Login button redirects to default page on valid login which is working as needed. But for forgot password button click, on clicking on this button, the page is not redirecting to forgot password page. On click of Login button after click on forgot password, however, page is being redirected to forgot password page.

my login page code is :

C#
protected void btnSelect_ServerClick(object sender, EventArgs e)
{

FormsAuthentication.RedirectFromLoginPage(userId, false);
}

my code in forgot password link button is:

C#
protected void lnkForgotPassword_Click(object sender, EventArgs e)
{
    Response.Redirect("ForgotPassword.aspx");
}


On click of forgotpassword, url shown in address bar is http://localhost:2040/GUI/Login.aspx?ReturnUrl=%2fGUI%2fForgotPassword.aspx[^] but page is not being redirected.

My web.config file is:

XML
<authentication mode="Forms">
      <forms name=".ASPXFORMSAUTH" defaultUrl="~/GUI/CompanySelect.aspx" loginUrl="~/GUI/Login.aspx" requireSSL="false" protection="All" slidingExpiration="true" path="/" enableCrossAppRedirects="false"/>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>


XML
<location path="~/GUI/ForgotPassword.aspx">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>
  </location>


how can I redirect to forgot password page on click of forgot password link? any help? Thanks in advance...
Posted
Comments
Abhipal Singh 20-May-15 2:24am    
What is the error you are getting on web browser?

Are you getting a page not found error?
If yes then, It looks like the URL you gave to Response.Redirect() is incorrect.
To check that can you post directory structure of your code?
Codes DeCodes 20-May-15 3:33am    
I am not getting any error at all.. on click of forgot password, nothing happens except for url in address bar changing to http://localhost:2040/GUI/Login.aspx?ReturnUrl=%2fGUI%2fForgotPassword.aspx[^] from http://localhost:2040/GUI/Login.aspx.
ZurdoDev 20-May-15 12:19pm    
1. Reply to the comment so that the user is notified.
2. If it is going back to login page that means you need to get the location element in web.config working because it's blocking access to ForgotPassword.aspx until you're authenticated. I'm not sure if the location path supports "~" so i would try without it. Web.config should be in root so do an absolute path.
Codes DeCodes 22-May-15 12:51pm    
I just noticed one thing. If I am connected to internet,my login page shows ads and page keeps on loading, in this case, forgot password is not being redirected. Else, if i am not connected to the internet, page loads instantly, so page is being redirected to default page...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900