Search code examples
visual-studio-2010visual-studiowindows-authenticationiis-express

IIS Express Windows Authentication


I'm trying to use IIS Express with VS2010 to host a silverlight application. I modified my applicationhost.config file to allow for modification of the proper configuration settings. I have the following in my web.config:

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

I am not being authenticated and my domain service call returns a null record as the user. I was able to get this to work after installing VS2010 SP1 BETA but I'm trying to get this to work with only IIS Express.

How do I enable Windows Authentication to work with IIS Express. Is there a configuration setting that I am missing?


Solution

  • option-1:

    edit \My Documents\IISExpress\config\applicationhost.config file and enable windowsAuthentication, i.e:

    <system.webServer>
    ...
      <security>
    ...
        <authentication>
          <windowsAuthentication enabled="true" />
        </authentication>
    ...
      </security>
    ...
    </system.webServer>
    

    option-2:

    Unlock windowsAuthentication section in \My Documents\IISExpress\config\applicationhost.config as follows

    <add name="WindowsAuthenticationModule" lockItem="false" />
    

    Alter override settings for the required authentication types to 'Allow'

    <sectionGroup name="security">
        ...
        <sectionGroup name="system.webServer">
            ...
            <sectionGroup name="authentication">
                <section name="anonymousAuthentication" overrideModeDefault="Allow" />
                ...
                <section name="windowsAuthentication" overrideModeDefault="Allow" />
        </sectionGroup>
    </sectionGroup>
    

    Add following in the application's web.config

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
          <security>
            <authentication>
              <windowsAuthentication enabled="true" />
            </authentication>
          </security>
        </system.webServer>
    </configuration>
    

    Below link may help: http://learn.iis.net/page.aspx/376/delegating-configuration-to-webconfig-files/

    After installing VS 2010 SP1 applying option 1 + 2 may be required to get windows authentication working. In addition, you may need to set anonymous authentication to false in IIS Express applicationhost.config:

    <authentication>
    
                <anonymousAuthentication enabled="false" userName="" />
    

    for VS2015, the IIS Express applicationhost config file may be located here:

    $(solutionDir)\.vs\config\applicationhost.config
    

    and the <UseGlobalApplicationHostFile> option in the project file selects the default or solution-specific config file.