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

16

110

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.

Lone answered 29/1, 2012 at 13:50 Comment(2)
are you running the IISExpress without administrative Privileges?Endolymph
So after banging my head on this for a while I finally realized it was because VS hadn't set a default page and apparently IISExpress.exe doesn't give folder listings to make that obvious.Fabricant
S
122

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.

Surfacetoair answered 8/7, 2013 at 7:13 Comment(9)
This is not specific to Visual Studio 2012, it can be made at least on Visual Studio 2010 too.Firstfoot
Worked for me in VS 2013.Inundate
This is the least invasive solution. This is likely how MS would want us to do this.Commix
You also need to disable Anonymous authentication.Particularity
In solution explorer click the the project name under solution node, then switch to Properties window, there you can see property Windows Authentication set it to EnabledLondalondon
Thanks for this!! This worked for me. We are using a custom roll provider and this needed to be set on the project.Valvulitis
I don't see this setting anywhere in the properties window. I am using VS 2015.Safko
This is only relevant if you are running your application in the debugger (F5), so it will be hosted in IIS Exress. If you are having authentication issues when attaching to an IIS application pool, then this answer does not apply.Inclining
See Tony L's answer below for detailed instructions.Journalese
B
102

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.

Biscay answered 16/8, 2012 at 13:23 Comment(6)
Visual Studio 2010 and 2012 can add this setting for you, per project, so that the global setting is not changed from its default, see https://mcmap.net/q/109653/-iis-express-windows-authenticationShona
I am trying that setting, because I am also getting this error in VS 2013 sporiadically, let's see if it helps, I'll let you know.Retention
Better if you use %userprofile%\documents\iisexpress\config\applicationhost.config. Mine was on D: (thanks Dan! danesparza.net/2014/09/…)Forevermore
This is the only solution worked for me, thanks a lot!Wileywilfong
Tried this in VS 2017 and it did not work. The solution posted by Jason did work.Wendel
There's a useful article on this, that clarifies all of the above (though a bit dated, it still works, even in 2019) here: digitaldrummerj.me/iis-express-windows-authenticationDumps
C
86

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

Commix answered 22/4, 2016 at 20:22 Comment(6)
Big thanks for spelling this out and specifying that it's the F4 properties that need to be changed.Laevo
Thank you! I had to set 'Anonymous Authentication' to 'Enabled' also.Attach
Big Thank You too!Delphadelphi
You are beautiful.Bullion
I'm using VS 2015, this does not exist!Safko
This is only relevant if you are running your application in the debugger (F5), so it will be hosted in IIS Exress. If you are having authentication issues when attaching to an IIS application pool, then this answer does not apply.Inclining
V
18

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

Vilma answered 25/9, 2014 at 13:49 Comment(0)
C
10

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://mcmap.net/q/196300/-iis-express-is-automatically-disabling-anonymous-authentication-for-my-project-why

Now I can access the login page as expected.

Classical answered 10/6, 2012 at 8:52 Comment(3)
I followed your steps still its not working for me. If opened from vs2010 it works fine, whats the issue in vs 2013Chevaldefrise
@user1016740 I'm not sure because there are a plethora of possibilities/paths to follow to try to solve this problem. The steps I described here solved it in my environment which I thinks is different from yours.Classical
The authentication configuration for your project doesn't belong into applicationHost.config. It should be in the web.config of your application.Inclining
B
8

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

Boonie answered 24/2, 2014 at 17:40 Comment(1)
This is super handy if you have ever edited your applicationhost.config to run a site on multiple ports at once. Removing the entries from the .config doesn't remove any reservations in netsh. Thanks man.Dorris
B
5

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

Bordie answered 26/11, 2013 at 0:42 Comment(0)
T
5

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!

Transoceanic answered 28/12, 2014 at 12:1 Comment(0)
K
2

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

Katti answered 14/7, 2017 at 7:42 Comment(1)
Okay, It helped to resolve the issue but now I have some other issues that I need to fix.Bedbug
J
1

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!

Junkman answered 22/9, 2015 at 20:47 Comment(0)
J
0

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>
Jobina answered 7/4, 2014 at 16:21 Comment(0)
R
0

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.

Rain answered 14/5, 2014 at 14:39 Comment(0)
R
0

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.

Rist answered 12/5, 2016 at 21:51 Comment(0)
A
0

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.

Acidity answered 27/9, 2016 at 13:14 Comment(0)
S
0

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.

Syllogistic answered 4/7, 2020 at 1:8 Comment(0)
D
0

I had almost the same error on 1 project I have been working on. All others projects were still OK. In my case , it was because all my projects are located on a network drive.

Somehow my 'previous projects' shortcut entry for this project was changed\ overwritten to using a mapped drive. Even though the mapped drive was valid and working, I would get this error.

Access is denied. Description: An error occurred while accessing the resources required to serve this request. You might not have permission to view the requested resources.

Error message 401.3: You do not have permission to view this directory or page using the credentials you supplied (access denied due to Access Control Lists). Ask the Web server's administrator to give you access to 'Y:...."

Close the project and use the UNC Path "\\networkdevice\path\project" .. to start the VS project and it all works fine. Silly little error, but maybe helps someone.

Dodson answered 24/9, 2023 at 21:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.