C# asp.net mvc4 中 web.config 中的 Windows 身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16815060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Authentication in web.config in asp.net mvc4
提问by zrabzdn
I need to enable Windows Authentication from my web.config, without setting it in IIS.
我需要从我的web.config.
I have the following elements in the web.config:
我有以下元素web.config:
authentication mode="Windows
identity impersonate="true
However windows authentication is not working. How do I resolve this problem ?
但是 Windows 身份验证不起作用。我该如何解决这个问题?
回答by Piotr Stapp
If windows authentication is not installed on IIS it won't work. If it is installed setting in web.config should be fine
如果 IIS 上未安装 Windows 身份验证,它将不起作用。如果在 web.config 中安装设置应该没问题
回答by Dimitar Dimitrov
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 身份验证”并标记为“已启用” -> 运行您的项目。
回答by Keith
Unfortunately you must use IIS to enable Windows authentication. You cannot do it in Web.config alone. (At least up to IIS 8.5, the current version as of this post.)
不幸的是,您必须使用 IIS 来启用 Windows 身份验证。您不能单独在 Web.config 中执行此操作。(至少到 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 身份验证 ( <system.webServer><security><authentication><windowsAuthentication>)的 Web.config 元素只能在 applicationHost.config (C:\Windows\System32\inetsrv\config) 中定义。
回答by Overflew
For IIS Express
对于 IIS Express
You can set it up here. You may also wish to disable anonymous access
你可以在这里设置。您可能还希望禁用匿名访问
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. The difference is that the config file avoids a manual step - but adds this next one:
这与@Dimitar 的建议几乎相同 - 使用 IIS 管理器更改设置。不同之处在于配置文件避免了手动步骤 - 但添加了下一个:
Note:
笔记:
By default, IIS Feature Delegationlocks 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. E.g.:
默认情况下,IIS 功能委派会锁定其中一些设置(基本和 Windows 身份验证),因此您需要转到 IIS 服务器的根目录,并启用这些设置为read/write。例如:
A more detailed description of accessing Feature Delegation is here.


