How to solve Redirect Loop

I have a web application, and some users who use Chrome as their preferred browser get the following error when they exit the application, and try to log in.

"This web page has a redirect cycle."

My web application uses forms authentication and FormAuthenticationModuleredirects the user to the login page of my application, so I cannot use this approach:

<customErrors mode="On" defaultRedirect="~/MyErrorPage.aspx" >

    <error statusCode="401" redirect="~/NoAccess.aspx"/>

</customErrors>

Instead, I added the following event of Page_Loadmine LoginPage.

if (Request.IsAuthenticated && !string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
{
    Response.Redirect("~/NoAccess.aspx");
}

However, since I added this approach, users seem to get a "Redirect Loop" error.

After clearing the cookies, everything looks good, but the problem arises again.

, , - , , ?

+5
4

web.config :

  <location path="NoAccess.aspx">
    <system.web>
      <authorization>
        <allow users="?"/>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

.

:

  <location path="Login.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

, . .

(, public/) ( ). :

  <location path="public">
    <system.web>
      <authorization>
        <allow users="?"/>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

. .

+7

IIS: Authentication Anonymous Authentication . , , , IIS ASP.NET. , , , @Grzegorz.

+2

, The request filtering module is configured to deny a request where the query string is too long. - Visual Studio 2013, .

URL- http://localhost:52266/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl...., URL- .

, , , .

:

  • . , ( ) "" ( , "", ).
  • Anonymous Authentication Enabled.
  • Windows Authentication Disabled.

, , .

+1

This is an old post, and I ran into this problem while user authentication and verification. The problem was solved by adding this line of code to web.config

<system.web>
<authentication mode="Forms">
  <forms name=".ASPXFORMSAUTH" path="/" timeout="240" cookieless="UseCookies"></forms>
</authentication>
<authorization>
  <allow users="*"/>
</authorization>
    <compilation debug="true" targetFramework="4.6" />
    <httpRuntime targetFramework="4.6" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
  </system.web> 

Hope this helps.

0
source

All Articles