繁体   English   中英

在IIS8上将Webapi与Windows身份验证结合使用时,在哪里可以找到用户身份

[英]Where can I find user identity when using webapi with Windows Authentication on IIS8

我试图找出如何在webapi中找到已登录用户的身份。 在开发服务器和较旧的IIS7上,可以在多个位置使用该标识,但是当我尝试在IIS8上设置我的应用程序时,所有已知来源都是空白。

使用<authentication mode="Windows" />我通常可以在以下位置看到用户身份:

System.Web.HttpContext.Current.User.Identity.Name
User.Identity.Name
Thread.CurrentPrincipal.Identity.Name

但是在IIS8上,它们全都空了。

在哪里寻找任何想法,或者如何配置IIS8或我的应用程序以查找用户身份?

ApiController.User

是您所需要的。 Web API不含System.Web,因此其行为有所不同。

您正在使用匿名用户进行身份验证。
您可以通过编辑web.config禁止匿名访问:

<system.web>
  <authorization>
    <deny users="?" />   <!-- The question-mark represents the `anonymous`-user) -->
  </authorization>
</system.web>

通常,当System.Web.HttpContext.Current.User.Identity.Name为空时,Windows身份验证失败。 看看HttpContext.Current.Request.IsAuthenticated

还要比较 IIS7和IIS8之间的设置
(应用程序池,web.config以及IIS身份验证设置

另一个问题可能是您正在使用的客户端(浏览器及其设置)。 也许浏览器没有提供Windows身份。

对于Internet Explorer,请验证:
Settings -> Advanced -> "Enable Integrated Windows Authentication*"

暂无
暂无

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

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