首页 > 解决方案 > ASP.NET Core IIS return DefaultAppPool instead of window user name

问题描述

I have used System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(); to get window user name in development mode but when I deploy it to IIS, it returns DefaultAppPool instead of window user name. I have enabled both window authentication an anonymous authentication in development mode.

标签: asp.net-coreiis-10

解决方案


WindowsIdentity.GetCurrent().Name是线程运行的标识。

如果要获取window用户,请禁用匿名认证。

然后使用:

HttpContext.Current.User.Identity.Name;

推荐阅读