New Asp.Net MVC5 project produces an infinite loop to login page

Highlight the project in Visual Studio

Open the 'Properties' panel on the right (or press F4)

Set 'Windows Authentication' to 'Disabled'

Set 'Anonymous Authentication' to 'Enabled'


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 are missing [AllowAnonymous] attribute on login action.

[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
    // code....
}

2nd possibility, specific to IIS Express only: is that, if you created same default WebApplication1 project multiple times, playing with different authentication settings, IIS Express stored additional authentication settings in it's configuration file. Something like:

    <location path="WebApplication1">
        <system.webServer>
            <security>
                <authentication>
                    <windowsAuthentication enabled="true" />
                    <anonymousAuthentication enabled="false" />
                </authentication>
            </security>
        </system.webServer>
    </location>
</configuration>

Configurations are in user's Documents folder Documents\IISExpress\config\, and you should look for:

applicationhost.config

Then just delete xml node <location path="WebApplication1"> mentioned above.


Update for VS 2015+

If you're using Visual Studio 2015 or higher, check this path for the config file: $(solutionDir)\.vs\config\applicationhost.config

Each solution will have its own config file.


I had to remove (Source Link):

<authorization>
  <deny users="?" />
</authorization>