Asked by:
Infinite Login Loop with Owin

Question
-
We have a major problem with login loops. Our asp.net mvc website is protected with organisational accounts, using owin. Login works well for a day or two, but after a couple of days, user gets trapped in a login-loop.
Flipping every other second between url, looking like this:
And so on. This is a major problem for us! I've re-written the login code several times, also ripped out everything and replaced the login code from a fresh asp.net mvc project created from VS2015. Deployed to a https url (I know there's been probs with non-https url logins)
If I restart or redeply the website, it works again for a day or two.
/Johan
Tuesday, December 1, 2015 10:33 AM
All replies
-
Hello,
This issue is because of the authentication mode selected(by default) by the MVC 5 Template, which triggers the ReturnUrl Style of redirection that might lead to an infinite loop if not configured correctly.
To disable OWIN startup discovery,add this key to your webconfig file.
<add key="owin:AutomaticAppStartup" value="false"/>
you can also refer this stackoverflow thred:
http://stackoverflow.com/questions/23065466/infinite-redirect-loop-for-basic-or-windows-authentication
Regards DOD...Tuesday, December 1, 2015 5:15 PM -
I'm afraid that's not it. If I add that setting, I'm never redirected to the microsoft azure ad login page. The whole website is supposed to be protected.
/Johan
Wednesday, December 2, 2015 1:06 PM -
Hello JoDan,
I understand that I could be too late for this. This issue can be caused, if you visit the application without HTTPS. Please refer to the link below as one of the use was able to resolve the issue:
https://github.com/aspnet/Security/issues/219
Thanks,
Syed Irfan Hussain- Proposed as answer by Syed Irfan Hussain Thursday, December 17, 2015 8:02 AM
Thursday, December 17, 2015 8:01 AM -
Thursday, April 21, 2016 1:33 PM
-
Hello Johan,
We are experiencing this exact same thing. Did you ever get it resolved and if so, what were the steps you took?
TIA...Bob Baldwin
AKA VSDotNetGuyTIA...vsdotnetguy
Friday, May 27, 2016 2:06 PM -
This one solved it for me. If this is on an App Service Web App, you might require HTTPS.
https://blogs.msdn.microsoft.com/benjaminperkins/2014/01/07/https-only-on-windows-azure-web-sites/
HTH, Benjamin
Wednesday, September 28, 2016 1:00 PM -
Thank you BenjaminPerkins!
My issue was caused by the Cookie manager issue where System.Web.Cookies conflicts with OWIN cookies and can cause the OWIN auth to fail.
The thing that drove me crazy was that the authentication would work once in a while and then fail after closing the browser and re-opening it. I, too, went ahead and set up a brand new MVC project with the same OWIN Startup. It worked fine on the brand new project that didn't make use of System.Web.Cookies and Sessions, yet. I was quite baffled.
Adding the custom cookie manager in the linked article fixed the issue for me. I am so relieved.
Wish I found this earlier, as I have been troubleshooting for hours and hours.
Friday, February 17, 2017 4:25 PM -
Hi,
is this fix still required in 5.0. It mentions that this was fixed ?
I have the same problem and its driving me crazy. A re-deploy will work for a while then the redirect starts again. Every day.
Rob
Rob
Thursday, October 12, 2017 8:59 AM -
Just to clarify, have you installed the 5.0 ver and still experiencing login loops? And do let us know if you are receiving any specific error message?
--------------------------------------------------------------------------------------------------
Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.
Tuesday, October 24, 2017 7:10 PMOwner -
Did you solve this problem? I have tried everything....Same as you it work after redeploy
CRM Consultant/Business Advisor at Skill AS in Norway
RockStar365 profileThursday, March 1, 2018 8:12 PM -
Take a look into this similar discussion thread and GitHub Page for some pointers.
If you have tried all the suggestions posted in this thread and the issues still persist, for a thorough analysis on this specific issue, you may raise a support ticket as mentioned in the link(s) below, which will help you work closely with the support for speedy resolution:
How to create an Azure support request or Technical Support for Microsoft Partners
---------------------------------------------------------------------------------------------------
Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.
- Edited by AjayKumar-MSFTMicrosoft employee, Owner Saturday, March 3, 2018 9:04 PM
Saturday, March 3, 2018 9:02 PMOwner