If you are using Visual Studio, you can also left-click on the project in Solution Explorer and change the Windows Authentication property to Enabled in the Properties window.
I just fixed this exact problem in IIS EXPRESS fixed it by editing the application host .config to the location section specific to the below. I had set Windows Authentication in Visual Studio 2012 but when I went into the XML it looked like this.
the windows auth tag needed to be added below as shown.
<windowsAuthentication enabled="true" />
<location path="MyApplicationbeingDebugged">
``<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<!-- INSERT TAG HERE -->
</authentication>
</security>
</system.webServer>
</location>
I've been struggling with this problem trying to create a simple App for SharePoint using Provider Hosted.
After going through the applicationhost.config, in the section, basicAuthentication was set to false. I changed it to true to get past the 401.2 in my scenario. There are plenty of other links of how to find the applicationhost.config for IIS Express.
Hosting on IIS Express:
1. Click on your project in the Solution Explorer to select the project.
2. If the Properties pane is not open, open it (F4).
3. In the Properties pane for your project:
a) Set "Anonymous Authentication" to "Disabled".
b) Set "Windows Authentication" to "Enabled".
None of the above had worked for me. This had been working for me prior to today. I then realized I had been working with creating a hosted connection on my laptop and had Shared an internet connection with my Wireless Network Connection.
To fix my issue:
Go to Control Panel > Network and Internet > Network Connections
Right click on any secondary Wireless Network Connection you may have (mine was named Wireless Network Connection 2) and click 'Properties'.
Go to the 'Sharing' tab at the top.
Uncheck the box that states 'Allow other network users to connect through this computer's Internet connection'.
I didn't see this "complete" answer anywhere; I just saw the one about changing port numbers after I posted this, so meh.
Make sure that in your project properties in visual studio that project url is not assigned to the same url or port that is being used in IIS for any site bindings.
I'm looking up the "why" for this, but my assumption off the top of my head is that both IIS and Visual Studio's IIS express use the same directory when creating virtual directories and Visual Studio can only create new virtual directories and cannot modify any that IIS has created when it applies it's bindings to the site.
In my case (ASP.NET MVC 4 application), the Global.asax file was missing. It was appearing in Solution explorer with an exclamation mark. I replaced it and the error went away.