C# asp.net mvc4中web.config中的Windows身份验证

C# asp.net mvc4中web.config中的Windows身份验证,c#,authentication,iis,asp.net-mvc-4,C#,Authentication,Iis,Asp.net Mvc 4,我需要从我的web.config启用Windows身份验证,而无需在IIS中进行设置 我在web.config中有以下元素: authentication mode="Windows identity impersonate="true 但是,windows身份验证不起作用。如何解决此问题?如果IIS上未安装windows身份验证,它将无法工作。如果在web.config中安装了它,则设置应该是正确的如果您的意思是从Visual Studio(IISExpress-而不是IIS)运行

我需要从我的
web.config
启用Windows身份验证,而无需在IIS中进行设置

我在
web.config
中有以下元素:

  authentication mode="Windows
  identity impersonate="true 

但是,windows身份验证不起作用。如何解决此问题?

如果IIS上未安装windows身份验证,它将无法工作。如果在web.config中安装了它,则设置应该是正确的

如果您的意思是从Visual Studio(IISExpress-而不是IIS)运行项目,则可以尝试执行以下操作:


在Visual Studio中->单击项目的根->按F4打开属性窗格->查找“Windows身份验证”并将其标记为“已启用”->运行项目。

不幸的是,您必须使用IIS来启用Windows身份验证。您不能仅在Web.config中执行此操作。(至少达到IIS 8.5,即本文发布时的当前版本。)


这是因为用于启用Windows身份验证的Web.config元素(
)只能在applicationHost.config(C:\Windows\System32\inetsrv\config)中定义。

用于IIS Express

你可以在这里设置。您可能还希望禁用匿名访问

适用于IIS

我发现有必要在
system.webServer

<system.webServer>
    […]
    <security>
      <authentication>
        <anonymousAuthentication enabled="false"/>
        <windowsAuthentication enabled="true"/>
      </authentication>
    </security>
  </system.webServer>

[…]


更详细的说明。

在Visual Studio中工作是否需要此功能?IISExpress?哪个版本的IIS?我需要它在IIS 7.0或7.5中工作