首页 > 解决方案 > 如何在 IIS 中获取 Windows 登录用户名定义匿名 + Windows 身份验证

问题描述

框架:ASP.NET CORE 2.2 作为 web-api 服务器:IIS-10 (Windows server 2016)

我需要同时使用WindowsAuthenticationAnonymousAuthentication。我有这两个选项以某种方式获取Windows LoggedIn User

User.Identity.Name; 

System.Security.Principal.WindowsIdentity.GetCurrent().Name 

我在一个匿名的端点(控制器方法)中使用它们。

IISExpress 一切正常,但是在使用 IIS(本地或部署后)时,我无法得到想要的结果:

User.Identity.Name; // return null

System.Security.Principal.WindowsIdentity.GetCurrent().Name //return IISAPPPOOL\<Application pool name>

应用程序池标识是 ApplicationPoolIdentity。

如何在此配置中获取Windows LoggedIn 用户名(匿名 + Windows 身份验证)?

标签: asp.net-core-2.0windows-authenticationiis-10applicationpoolidentity

解决方案


推荐阅读