简体   繁体   English

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

[英]Windows Authentication in web.config in asp.net mvc4

I need to enable Windows Authentication from my web.config , without setting it in IIS. 我需要从我的web.config启用Windows身份验证,而不在IIS中设置它。

I have the following elements in the web.config : 我在web.config有以下元素:

  authentication mode="Windows
  identity impersonate="true 

However windows authentication is not working. 但是Windows身份验证不起作用。 How do I resolve this problem ? 我该如何解决这个问题?

For IIS Express 对于IIS Express

You can set it up here. 你可以在这里设置它。 You may also wish to disable anonymous access 您可能还希望禁用匿名访问

为IIS Express设置Windows身份验证

For IIS 对于IIS

I found it was necessary to set this under system.webServer 我发现有必要在system.webServer下设置它

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

This does almost the same thing as the @Dimitar suggestion - use IIS Manager to change the setting. 这与@Dimitar建议几乎完全相同 - 使用IIS管理器更改设置。 The difference is that the config file avoids a manual step - but adds this next one: 区别在于配置文件避免了手动步骤 - 但是添加下一个:

Note: 注意:

By default, IIS Feature Delegation locks some of those settings (Basic & Windows auth), so you'll need to go to the root of the IIS server, and enable those to be read/write . 默认情况下, IIS功能委派会锁定其中一些设置(基本和Windows身份验证),因此您需要转到IIS服务器的根目录,并启用它们进行读/写 Eg: 例如:

功能委派 - 允许对auth部分进行读/写

A more detailed description of accessing Feature Delegation is here . 有关访问功能委派的更详细说明,请参见此处

If by this you mean running your project from Visual Studio (IISExpress - not IIS), then you can try to do the following: 如果你的意思是从Visual Studio(IISExpress而不是IIS)运行你的项目,那么你可以尝试执行以下操作:

In Visual Studio -> Click on the root of your project -> Press F4 in order to open the properties pane -> Look for "Windows Authentication" and mark is as "Enabled" -> Run your project. 在Visual Studio中 - >单击项目的根目录 - >按F4以打开属性窗格 - >查找“Windows身份验证”并标记为“已启用” - >运行项目。

Unfortunately you must use IIS to enable Windows authentication. 遗憾的是,您必须使用IIS来启用Windows身份验证。 You cannot do it in Web.config alone. 您无法单独在Web.config中执行此操作。 (At least up to IIS 8.5, the current version as of this post.) (至少达到IIS 8.5,这篇文章的当前版本。)

This is because the Web.config elements for enabling Windows authentication ( <system.webServer><security><authentication><windowsAuthentication> ) can only be defined in applicationHost.config (C:\\Windows\\System32\\inetsrv\\config). 这是因为用于启用Windows身份验证的Web.config元素( <system.webServer><security><authentication><windowsAuthentication> )只能在applicationHost.config(C:\\ Windows \\ System32 \\ inetsrv \\ config)中定义。

If windows authentication is not installed on IIS it won't work. 如果IIS上没有安装Windows身份验证,它将无法正常工作。 If it is installed setting in web.config should be fine 如果在web.config中安装设置应该没问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM