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

1

Good afternoon,

I'm 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 get complicated when I want to use FormsAuthentication that causes the infinite relay error and can not open the site, reaching the limit. I already changed maxUrl and maxUrl and nothing.

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

I have 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 have also cleaned Chrome Cookies and nothing, tried other browsers and the problem appears the same or worse. What am I doing wrong? What is the solution to my problem?

    
asked by anonymous 14.04.2016 / 17:00

1 answer

1
  

Changing MaxUrl is like solving a performance problem by putting a   Stronger CPU.

You are using both options at the same time

FormsAuthentication.RedirectFromLoginPage

and

Response.Redirect

Being both make a redirect.

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

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

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");
}
    
14.04.2016 / 18:01