ASP.Net MVC undefined redirect loop

I have an ASP.Net MVC5 application using the Identity template out of the box according to ASP.Net Identity 2.0.0. I need to update it to use the new code that is in the latest ASP.Net MVC pattern, namely using the SignInManager class.

I did some A / B comparisons between the code in my original application and the template generated by the last one and ported everything I could see that is different.

However I am getting a weird error, I suspect OWIN is linked. When I try to login and register, it starts a Redirect loop, which eventually crashes the application with a security warning as the URL query string is concatenated to death.


Url: https: // localhost:44302 / Account / Login? ReturnUrl =% 2FAccount% 2FLogin% 3FReturnUrl% 3D% 252FAccount% 252FLogin% 253FReturnUrl% 253D% 25252FAccount% 25252FLogin% 25253FReturnUrl% 25253D% 2525252FAccount% 2525252FLogin% 2525253FReturnUrl% 2525253D% 252525252FAccount% 252525252FLogin% 252525253FReturnUrl% 252525253D% 25252525252FAccount % 25252525252FLogin% 25252525253FReturnUrl% 25252525253D% 2525252525252FAccount% 2525252525252FLogin% 2525252525253FReturnUrl% 2525252525253D% 252525252525252FAccount% 252525252525252FLogin% 252525252525253FReturnUrl% 252525252525253D% 25252525252525252FAccount% 25252525252525252FLogin% 25252525252525253FReturnUrl% 25252525252525253D% 2525252525252525252FAccount% 2525252525252525252FLogin% 2525252525252525253FReturnUrl% 2525252525252525253D% 252525252525252525252FAccount% 252525252525252525252FLogin% 252525252525252525253FReturnUrl% 252525252525252525253D% 25252525252525252525252FAccount% 25252525252525252525252FLogin% 25252525252525252525253FReturnUrl% 25252525252525252525253D% 2525252525252525252525252FAccount% 2525252525252525252525252FLogin% 2525252525252525252525253FReturnUrl% 2525252525252525252525253D% 252525252525252525252525252FAccount% 252525252525252525252525252FLogin% 252525252525252525252525253FReturnUrl% 252525252525252525252525253D% 25252525252525252525252525252FAccount% 25252525252525252525252525252FLogin% 25252525252525252525252525253FReturnUrl% 25252525252525252525252525253D% 2525252525252525252525252525252FAccount% 2525252525252525252525252525252FLogin% 2525252525252525252525252525253FReturnUrl% 2525252525252525252525252525253D% 252525252525252525252525252525252FAccount% 252525252525252525252525252525252FLogin% 252525252525252525252525252525253FReturnUrl% 252525252525252525252525252525253D% 25252525252525252525252525252525252FAccount% 25252525252525252525252525252525252FLogin% 25252525252525252525252525252525253FReturnUrl% 25252525252525252525252525252525253D% 2525252525252525252525252525252525252FAccount% 2525252525252525252525252525252525252FLogin% 2525252525252525252525252525252525253FReturnUrl% 2525252525252525252525252525252525253D% 252525252525252525252525252525252525252FAccount% 252525252525252525252525252525252525252FLogin

Details of the error:

module RequestFilteringModule

BeginRequest Notification

Handler ExtensionlessUrlHandler-Integrated-4.0

Error code 0x00000000


I used the same settings when referencing ReturnUrl in all methods.

For the most part, my apps' original AccountController instance and associated security code were untouched from the original template. My new sample app works fine on my local machine, so I'm not sure where the differences are.

I saw messages indicating that the IIS Express configuration was at fault, but I followed the cleaning advice and also posted an Azure site with the same result.

I spent a lot of time trying to resolve this and had no success, so figured I put it there for some advice ... well in advance for any help. Please let me know if you need to see more code.

+3


source to share


4 answers


Solved ... it turns out my Unity DI configuration was the culprit.

I drilled deep to find errors recursively thrown on every redirect, and he assumed the AccountController dependencies had not been created. I had a similar issue last year with Unity Container trying to resolve an unregistered type, throw error , and so I looked further at the changed dependencies.



As per the suggested answer to Registering the IAuthenticationManager with Unity resolved the issue.

Thanks for the suggestions re: SSL / HTTPS / Filters, investigating which led me to exceptions.

+2


source


I think your login action has no attribute [AllowAnonymous]

.



+5


source


Do you have SSL setup locally? Authentication to HTTPS is then redirected to HTTP which kills the cookie and redirects back to the HTTPS login page

You have something in your web.config file to relay forms authentication like

  protection="All" requireSSL="true" loginUrl="~/Account/Login.aspx"

      

Are your cookies doing ok?

+2


source


I also face this same problem before and solve by adding this line to the web config

<add key="owin:AutomaticAppStartup" value="false"/>

      

It will disable OWIN startup detection.

I hope this works.

Also check the IIS virtual directory. Make sure anonymous user is enabled or not, if disabled, enable it and the problem will be resolved.

0


source







All Articles