IIS Express HTTP错误401.2 - 未经授权

And*_*May 21 .net-4.0 windows-authentication iis-express

我已尝试过这篇文章中的建议,但我无法在Vision Studio 2010中使用IIS身份验证进行Windows身份验证.现在我收到以下错误: 401.2错误

这是我的applicationhost.config文件条目:

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

    <anonymousAuthentication enabled="true" userName="" />

    <basicAuthentication enabled="false" />

    <clientCertificateMappingAuthentication enabled="false" />

    <digestAuthentication enabled="false" />

    <iisClientCertificateMappingAuthentication enabled="false">
    </iisClientCertificateMappingAuthentication>

    <windowsAuthentication enabled="true" />
</authentication>
...
<sectionGroup name="authentication">
    <section name="anonymousAuthentication" overrideModeDefault="Allow" />
    <section name="basicAuthentication" overrideModeDefault="Allow" />
    <section name="clientCertificateMappingAuthentication" overrideModeDefault="Allow" />
    <section name="digestAuthentication" overrideModeDefault="Allow" />
    <section name="iisClientCertificateMappingAuthentication" overrideModeDefault="Allow" />
    <section name="windowsAuthentication" overrideModeDefault="Allow" />
</sectionGroup>
Run Code Online (Sandbox Code Playgroud)

我的web.config:

<system.web>
    <authentication mode="Windows" /> 
</system.web>
<system.webServer>
    <security>
        <authentication>
            <anonymousAuthentication enabled="false" />
            <windowsAuthentication enabled="true" />        
        </authentication>
    </security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

这是.NET 4

vik*_*all 34

确保applicationhost.config文件中包含类似下面的内容

<windowsAuthentication enabled="true">
  <providers>
    <add value="Negotiate" />
    <add value="NTLM" />
   </providers>
</windowsAuthentication>
Run Code Online (Sandbox Code Playgroud)

这个文件可能在 %HOMEPATH%\Documents\IISExpress\config\

  • 这由问题解决,它是关于行号388.默认是"假" (3认同)
  • 对于 .NET Core,`applicationhost.config` 文件位于解决方案目录的 .vs 文件夹中。 (3认同)
  • applicationhost.config文件可能位于C:\ Users\yourname\Documents\IISExpress\config中 (2认同)

Jan*_*sek 5

当我想更新服务参考时,在带有IIS 8.0 Express的VS 2013中遇到了这样的问题。弹出对话框,询问用户名/密码。一个奇怪的子字符串被添加到服务URL:

_vti_bin/ListData.svc
Run Code Online (Sandbox Code Playgroud)

我开始配置Windows身份验证,如在applicationhost.config的本页中的某些帖子中所述。最后,工作配置不能具有协商提供程序:

<windowsAuthentication enabled="true">
  <providers>
    <!--<add value="Negotiate" />-->
    <add value="NTLM" />
   </providers>
</windowsAuthentication>
Run Code Online (Sandbox Code Playgroud)

并且必须禁用匿名身份验证:

<anonymousAuthentication enabled="false" />
<windowsAuthentication enabled="true" />
Run Code Online (Sandbox Code Playgroud)

  • 取消协商是触发条件!我已经尝试了stackoverflow针对此一般401问题提到的所有其他内容。因此,唯一需要解决的问题是设置windowsAuthentication enabled = true并注释掉“ Negotiate”。我在applicationHost.config和Web项目上的Visual Studio属性中同时启用了匿名身份验证和Windows身份验证。 (2认同)