MVC的Web API将不会允许Windows身份验证 [英] MVC Web Api won't allow Windows Authentication

查看:766
本文介绍了MVC的Web API将不会允许Windows身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的MVC Web API 2 IIS托管的应用程序,我想启用Windows身份验证(最初不使用Owin)。我是我的开发机器上运行此运行本地IIS。

I have a simple MVC web api 2 IIS hosted application which I want to enable windows authentication (initially not using Owin). I am running this on my development machine and running as local IIS.

所以,从我能找到的,我需要将以下添加到Web.config

So, from what I could find, I need to add the following to the web.config

1:以下部分的身份验证模式=窗口

1: to the following section the authentication mode="Windows"

<system.web>
  <compilation debug="true" targetFramework="4.5.1"/>
  <httpRuntime targetFramework="4.5.1"/>
  <authentication mode="Windows" />
</system.web>

2:然后添加以下

2: Then add the following

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

当我添加上面并运行(从开发工作室调试)的应用程序,我得到以下错误

When I add the above and run the application (in debug from Dev studio), I get the following error

HTTP错误500.19 - 内部服务器错误

配置错误此配置节不能在这个路径中使用。当部分在一父级别锁定发生这种情况。锁定或者是默认设置的(overrideModeDefault =拒绝),或通过包含overrideMode位置标记=拒绝或旧有的allowOverride =false的显式设置。

Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".

,然后将其明确指向此web配置条目

and then it specifically points to this web config entry

配置来源:

37:     <authentication>
38:       <windowsAuthentication enabled="true"/>
39:     </authentication>

任何人有任何想法,为什么我会得到这个?

Anyone have any ideas why I would be getting this?

另外,我注意到当我切换到IIS前preSS,即在项目属性中,Windows身份验证设置为禁用,并呈灰色,所以我不能设置在这里无论是。

Also, I noticed when I switch to IIS express, that in the project properties, the Windows Authentication is set to disabled, and grayed out so I cannot set it here either.

在此先感谢您的帮助!

推荐答案

如果你读的applicationHost.config,你会看到认证相关部分被锁定,不能在web.config中被重写,

If you read applicationHost.config, you will see that authentication related sections are locked down and cannot be overridden in web.config,

&lt;节名称=windowsAuthenticationoverrideModeDefault =拒绝/&GT;

因此​​,你需要指定的的applicationHost.config。 IIS和IIS防爆preSS两者都有这样的限制。

Thus, you need to specify that in applicationHost.config. Both IIS and IIS Express have such restriction.

这篇关于MVC的Web API将不会允许Windows身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆