【问题标题】:ASP.Net Core 2.2 MVC Windows authentication and windows username issue on IISIIS 上的 ASP.Net Core 2.2 MVC Windows 身份验证和 Windows 用户名问题
【发布时间】:2019-02-18 17:55:38
【问题描述】:

我正在开发 ASP.Net core 2.2 MVC 应用程序。使用 Windows 身份验证对用户进行身份验证,我想在成功登录后在我的主页中显示已登录的用户。

如何使用以下函数/方法来获取在调试模式下正常工作的用户名。

但是当我托管在 IIS 中时,我没有得到用户名,而是得到了

应用程序池名称、机器名称

       ViewBag.username = Environment.UserName;
        ViewBag.username = Environment.GetEnvironmentVariable("USERNAME");
        ViewBag.username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
        ViewBag.username = User.FindFirst(ClaimTypes.NameIdentifier).ToString();

下面的代码是错误的请求 500 IHttpContextAccessor

当我使用时

ViewBag.username = this.User.Identity.Name;

我收到环境变量错误,敏感信息正在传递,因为它传递了用户名。

所以到目前为止没有任何工作,任何解决方案都在挖掘更多来自 MS 和论坛的所有文档,但还没有解决方案。

已经检查了以下线程

Asp.Net Core 2.1 Windows Auth. HttpContext.User.Identity.Name not working in IIS

感谢任何人能给我正确的解决方案。

【问题讨论】:

    标签: .net-core windows-authentication


    【解决方案1】:

    “带有敏感信息的环境变量错误正在传递,因为它传递了用户名。”是常见错误,因为它不会在生产环境中显示确切的错误。 禁用匿名身份验证。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2021-07-11
      相关资源
      最近更新 更多