【问题标题】:ASP.NET Core IIS return DefaultAppPool instead of window user nameASP.NET Core IIS 返回 DefaultAppPool 而不是窗口用户名
【发布时间】:2021-10-07 11:14:39
【问题描述】:

我使用过 System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();在开发模式下获取窗口用户名,但是当我将其部署到 IIS 时,它返回 DefaultAppPool 而不是窗口用户名。我在开发模式下启用了窗口身份验证和匿名身份验证。

【问题讨论】:

标签: asp.net-core iis-10


【解决方案1】:

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

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

然后使用:

HttpContext.Current.User.Identity.Name;

【讨论】:

  • 我同时使用匿名认证和窗口认证,所以这个方法不适合我,可以推荐其他方法吗?
  • 如果匿名认证和windows认证都开启了,当用户匿名认证时,应用程序如何获取用户名?据我所知,匿名认证中没有任何方法可以获取用户名。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-07
  • 1970-01-01
  • 1970-01-01
  • 2019-08-08
  • 1970-01-01
相关资源
最近更新 更多