c# - How to solve Redirect Loop -


i have web application, , users use chrome preferred browser of choice, following error when have logged out of application, , try log in.

"this webpage has redirect loop".

my web application uses forms authentication, , formauthenticationmodule redirects user login page of application, cannot use approach:

<customerrors mode="on" defaultredirect="~/myerrorpage.aspx" >      <error statuscode="401" redirect="~/noaccess.aspx"/>  </customerrors> 

instead, have added following page_load event of loginpage.

if (request.isauthenticated && !string.isnullorempty(request.querystring["returnurl"])) {     response.redirect("~/noaccess.aspx"); } 

however, since have added approach, users seem "redirect loop" error.

after clearing cookies, seems well, problem occur again.

is there permanent fix can add code, or there else can prevent issue happening?

try adding web.config file:

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

this turn off authorization page , should stop loop.

you can add this:

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

this deny access login page users authenticated. combining 2 should allow add custom errors redirections.

you may consider creating directory unauthorized access (eg. public/) , placing inside error pages (that not require being authorized). can do:

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

you can read more location here. , more authorization here.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -