locked
Always redirects to login page RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    I have implemented form authentication in my project by gone through some article on net.

    But After implementing form authentication it goes in same block( where user id and password match) but redirects to Login.aspx instead of mentioned page in that block.

    if (status == 1)
            {
                 // user id and password exists 
                if (FormsAuthentication.Authenticate(txtUserId.Value.ToString(), txtPassword.Value.ToString()))
                {
                    FormsAuthentication.RedirectFromLoginPage(txtUserId.Value.ToString(), false);
                    Response.Redirect("Dash_Board.aspx");
                }
                else
                {
                  
                }  
               
    
               
            }

    Web config
    
    <system.web>
        <authentication mode="Forms">
          <forms loginUrl="Login.aspx" defaultUrl="Dash_Board.aspx">
            
          </forms>
        </authentication>
        <authorization>
          <deny users="?"/>
        </authorization>

    Please suggest.
     

    Saturday, March 17, 2018 5:24 AM

Answers

  • User283571144 posted

    Hi demoninside9,

    According to your description and code, I have created a test demo on my side, it could works well.

    I suggest you could firstly set the breakpoint at this line(if (FormsAuthentication.Authenticate(txtUserId.Value.ToString(), txtPassword.Value.ToString()))) to make sure the user has already login in.

    More details about my test demo, you could refer to below codes:

    Login button click event:

            protected void Button1_Click(object sender, EventArgs e)
            {
                FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,
    false);
            }

    Dash_Board page code-behind:

            protected void Page_Load(object sender, EventArgs e)
            {
                Response.Write("Username : " + HttpContext.Current.User.Identity.Name);
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                FormsAuthentication.SignOut();
            }

    Web config:

        <authentication mode="Forms">
          <forms loginUrl="Login.aspx"   defaultUrl="Dash_Board.aspx">
          </forms>
        </authentication>
        <authorization>
          <deny users="?"/>
        </authorization>

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 19, 2018 7:10 AM