After upgrading from MVC 4 to MVC 5, my application (when started from within Visual Studio) gives the following error. It might also be worth noting that I am hosting both
If you are running your app locally and getting an http 401 error then you may need to change your IISExpress configuration. Go to Documents>IISExpress>applicationhost.config
Make sure windowsAuthentication is enabled:
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>
In addition to the above answers, depending on which template was used to create the project you may have Startup.Auth.cs in the App_Start folder with the following code which can be commented out:
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
I was able to resolve the issue by adding the following to the appSettings section as per the response to this question.
<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>
In addition, Web.Config System.web section should NOT contain this line:
<authentication mode="Forms" />
And in my case it worked.