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

137,091

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.

  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

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.

Share:
137,091

Related videos on Youtube

Kris-I
Author by

Kris-I

.NET Consulting

Updated on July 08, 2022

Comments

  • Kris-I
    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
      emily-bcot over 12 years
      are you running the IISExpress without administrative Privileges?
    • B.Z.B
      B.Z.B almost 10 years
      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.
  • Robert Claypool
    Robert Claypool about 11 years
    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 stackoverflow.com/a/7168308/23566
  • Loïc Lopes
    Loïc Lopes over 10 years
    This is not specific to Visual Studio 2012, it can be made at least on Visual Studio 2010 too.
  • Dusda
    Dusda about 10 years
    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.
  • GANI
    GANI about 10 years
    I followed your steps still its not working for me. If opened from vs2010 it works fine, whats the issue in vs 2013
  • Leniel Maccaferri
    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
    kaybee99 over 9 years
    Worked for me in VS 2013.
  • Tony L.
    Tony L. almost 9 years
    This is the least invasive solution. This is likely how MS would want us to do this.
  • Matt
    Matt almost 9 years
    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.
  • Glazed
    Glazed over 8 years
    You also need to disable Anonymous authentication.
  • Jeramy Rutley
    Jeramy Rutley over 8 years
    Better if you use %userprofile%\documents\iisexpress\config\applicationhost.co‌​nfig. Mine was on D: (thanks Dan! danesparza.net/2014/09/…)
  • Mohammad Anini
    Mohammad Anini about 8 years
    This is the only solution worked for me, thanks a lot!
  • PeterDNCO
    PeterDNCO over 7 years
    Big thanks for spelling this out and specifying that it's the F4 properties that need to be changed.
  • Mahesh
    Mahesh almost 7 years
    Thank you! I had to set 'Anonymous Authentication' to 'Enabled' also.
  • FunMatters
    FunMatters about 6 years
    Big Thank You too!
  • myroslav
    myroslav almost 6 years
    Tried this in VS 2017 and it did not work. The solution posted by Jason did work.
  • sairfan
    sairfan about 5 years
    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 Enabled
  • kosherjellyfish
    kosherjellyfish about 5 years
    You are beautiful.
  • Bindum
    Bindum about 5 years
    Thanks for this!! This worked for me. We are using a custom roll provider and this needed to be set on the project.
  • Mark Bonafe
    Mark Bonafe over 4 years
    I don't see this setting anywhere in the properties window. I am using VS 2015.
  • Mark Bonafe
    Mark Bonafe over 4 years
    I'm using VS 2015, this does not exist!
  • Jamshaid K.
    Jamshaid K. over 4 years
    Okay, It helped to resolve the issue but now I have some other issues that I need to fix.
  • Paul
    Paul over 3 years
    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-authentication
  • Florian Winter
    Florian Winter over 3 years
    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.
  • Florian Winter
    Florian Winter over 3 years
    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.
  • Florian Winter
    Florian Winter over 3 years
    The authentication configuration for your project doesn't belong into applicationHost.config. It should be in the web.config of your application.
  • ErikusMaximus
    ErikusMaximus about 3 years
    See Tony L's answer below for detailed instructions.