【发布时间】: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