Formsauthentication causes an infinite redirect error - ASP.NET C#

Asked

Viewed 182 times

1

Good afternoon,

I am developing an ASP.NET application with C# that requires login, works and is being used this way:

protected void Page_Load(object sender, EventArgs e)
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FARMConnectionString"].ConnectionString);
                conn.Open();
                string checkuser = "select count(*) from colaboradores where nrColaborador='" + TextBox1.Text + "'";
                SqlCommand com = new SqlCommand(checkuser, conn);
                int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
                conn.Close();
                if (temp == 1)
                {
                    conn.Open();
                    string checkPasswordQuery = "select psw from colaboradores where nrColaborador='" + TextBox1.Text + "'";
                    SqlCommand passCom = new SqlCommand(checkPasswordQuery, conn);
                    string password = passCom.ExecuteScalar().ToString().Replace(" ", " ");

                    if (password == TextBox2.Text)
                    {
                        Session["New"] = TextBox1.Text;

                        FormsAuthentication.RedirectFromLoginPage(temp.ToString(), true);
                        Response.Redirect("Menu.aspx");
                    }
                    else
                    {
                        Response.Write("Username ou Password errados");
                    }
                }              
            }

So far so good, things complicate when I want to use the FormsAuthentication that causes the error of infinite forwarding and can not open the site, reaching the limit. I’ve already changed the maxUrl and the maxUrl and nothing.

<requestLimits maxUrl="10999" maxQueryString="2097151" />

I’ve already modified the authentication-mode and the authorizathion and also nothing:

<authentication mode="Forms">
      <forms loginUrl="Login.aspx" defaultUrl="Menu.aspx"/>
    </authentication>

      <authorization>
        <deny users="?"/>
      </authorization>

I’ve also cleared Chrome Cookies and nothing, tried with other browser and the problem appears equal or worse. What am I doing wrong? What is the solution to my problem?

1 answer

1


Changing Maxurl equals solving performance problem by placing a Stronger CPU.

You are using the 2 options at the same time

FormsAuthentication.RedirectFromLoginPage

and

Response.Redirect

Both of which make a redirect.

Redirectfromloginpage: Redirects an authenticated user back to the originally requested URL or default URL.

In your case above you using the 2... remove a.

The idea would be something like

if (password == TextBox2.Text)
{
      Session["New"] = TextBox1.Text;
      FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, true);

} else{
     Response.Write("Username ou Password errados");
}
  • Good morning, I apologize for the delay in answering. I did as indicated but that same error continues, it is possible that I am missing some part of code?

Browser other questions tagged

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