IIS Express gives Access Denied error when debugging ASP.NET MVC
Solution 1
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
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
I used Jason's answer but wanted to clarify how to get in to properties.
- Select project in Solution Explorer
- F4 to get to properties (different than the right click properties)
- Change Windows Authentication to Enabled
Solution 4
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
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.
Related videos on Youtube
Comments
-
Kris-I almost 2 years
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.
-
emily-bcot over 12 yearsare you running the IISExpress without administrative Privileges?
-
B.Z.B almost 10 yearsSo 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.
-
-
Robert Claypool about 11 yearsVisual Studio 2010 and 2012 can add this setting for you, per project, so that the global setting is not changed from its default, see stackoverflow.com/a/7168308/23566
-
Loïc Lopes over 10 yearsThis is not specific to Visual Studio 2012, it can be made at least on Visual Studio 2010 too.
-
Dusda about 10 yearsThis 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.
-
GANI about 10 yearsI followed your steps still its not working for me. If opened from vs2010 it works fine, whats the issue in vs 2013
-
Leniel Maccaferri about 10 years@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.
-
kaybee99 over 9 yearsWorked for me in VS 2013.
-
Tony L. almost 9 yearsThis is the least invasive solution. This is likely how MS would want us to do this.
-
Matt almost 9 yearsI 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.
-
Glazed over 8 yearsYou also need to disable Anonymous authentication.
-
Jeramy Rutley over 8 yearsBetter if you use %userprofile%\documents\iisexpress\config\applicationhost.config. Mine was on D: (thanks Dan! danesparza.net/2014/09/…)
-
Mohammad Anini about 8 yearsThis is the only solution worked for me, thanks a lot!
-
PeterDNCO over 7 yearsBig thanks for spelling this out and specifying that it's the F4 properties that need to be changed.
-
Mahesh almost 7 yearsThank you! I had to set 'Anonymous Authentication' to 'Enabled' also.
-
FunMatters about 6 yearsBig Thank You too!
-
myroslav almost 6 yearsTried this in VS 2017 and it did not work. The solution posted by Jason did work.
-
sairfan about 5 yearsIn 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 Enabled
-
kosherjellyfish about 5 yearsYou are beautiful.
-
Bindum about 5 yearsThanks for this!! This worked for me. We are using a custom roll provider and this needed to be set on the project.
-
Mark Bonafe over 4 yearsI don't see this setting anywhere in the properties window. I am using VS 2015.
-
Mark Bonafe over 4 yearsI'm using VS 2015, this does not exist!
-
Jamshaid K. over 4 yearsOkay, It helped to resolve the issue but now I have some other issues that I need to fix.
-
Paul over 3 yearsThere'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-authentication
-
Florian Winter over 3 yearsThis 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.
-
Florian Winter over 3 yearsThis 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.
-
Florian Winter over 3 yearsThe authentication configuration for your project doesn't belong into
applicationHost.config
. It should be in theweb.config
of your application. -
ErikusMaximus about 3 yearsSee Tony L's answer below for detailed instructions.