IIS Express gives Access Denied error when debugging ASP.NET MVC

asp.net MvcDebuggingIisIis ExpressAccess Denied

asp.net Mvc Problem Overview


I have created an ASP.NET MVC 3 project, and am using IIS Express as the web server when developing. When I try to debug, I get the error message below.

How can this be solved?

>Server Error in '/' Application.

>Access is denied. Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

>Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

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.

Solution 2 - asp.net Mvc

The cause if had for this problem was IIS Express not allowing WindowsAuthentication. This can be enabled by setting

<windowsAuthentication enabled="true">

in the applicationhost.config file located at C:\Users[username]\Documents\IISExpress\config.

Solution 3 - asp.net Mvc

I used Jason's answer but wanted to clarify how to get in to properties.

  1. Select project in Solution Explorer

enter image description here

  1. F4 to get to properties (different than the right click properties)
  2. Change Windows Authentication to Enabled

enter image description here

Solution 4 - asp.net Mvc

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".

Solution 5 - asp.net Mvc

In my case I had to open the file:

C:\...\Documents\IISExpress\config\applicationhost.config

I had this inside the file:

  <authentication>
  <anonymousAuthentication enabled="true" User="" />

I just removed the User="" part. I really don't know how this thing got there... :)

Note: Make sure you have something like this in the end of applicationhost.config:

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

You may also want to take a look here: https://stackoverflow.com/a/10041779/114029

Now I can access the login page as expected.

Solution 6 - asp.net Mvc

In my case a previous run of my app from VS reserved the URL. I could see this by running in a console:

netsh http show urlacl

to delete this reservation i ran this in an elevated console:

netsh http delete urlacl http://127.0.0.1:10002/

I found these steps here solved my problem.

I'm using VS2013

Solution 7 - asp.net Mvc

I had to run Visual Studio in Administrative Mode to get rid of this error.

Solution 8 - asp.net Mvc

I had also the same problem and finally I could overcame it.

Solution ExplorerRight click on projectPropertiesWeb tabProject Url

I have chosen another port number, and every things became fine!

Solution 9 - asp.net Mvc

I opened my web.config file, and found and removed this section:

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

and my site came up, but there are issuues with the authentication..

Solution 10 - asp.net Mvc

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'.

Hit OK > then Apply.

Hope this helps!

Solution 11 - asp.net Mvc

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>

Solution 12 - asp.net Mvc

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.

Solution 13 - asp.net Mvc

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.

feel free to correct me on the why.

Solution 14 - asp.net Mvc

Our error page was behind the login page, but the login page had an error in one of the controls, which creates an infinite loop.

We removed all the controls from the offending page, and added them back one by one until the correct control was located and fixed.

Solution 15 - asp.net Mvc

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKris-IView Question on Stackoverflow
Solution 1 - asp.net MvcJasonView Answer on Stackoverflow
Solution 2 - asp.net MvcAnt SwiftView Answer on Stackoverflow
Solution 3 - asp.net MvcTony L.View Answer on Stackoverflow
Solution 4 - asp.net MvcDanielView Answer on Stackoverflow
Solution 5 - asp.net MvcLeniel MaccaferriView Answer on Stackoverflow
Solution 6 - asp.net MvcBillDarcyView Answer on Stackoverflow
Solution 7 - asp.net MvcSerj SaganView Answer on Stackoverflow
Solution 8 - asp.net MvcfrogattoView Answer on Stackoverflow
Solution 9 - asp.net MvckfnView Answer on Stackoverflow
Solution 10 - asp.net MvcRyan CView Answer on Stackoverflow
Solution 11 - asp.net Mvcuser3507561View Answer on Stackoverflow
Solution 12 - asp.net MvckfrostyView Answer on Stackoverflow
Solution 13 - asp.net Mvcuser1040975View Answer on Stackoverflow
Solution 14 - asp.net MvcAtron SeigeView Answer on Stackoverflow
Solution 15 - asp.net MvcMoses MachuaView Answer on Stackoverflow