Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net core IIS上的ASP.Net Core 2.2 MVC Windows身份验证和Windows用户名问题_.net Core_Windows Authentication - Fatal编程技术网

.net core IIS上的ASP.Net Core 2.2 MVC Windows身份验证和Windows用户名问题

.net core IIS上的ASP.Net Core 2.2 MVC Windows身份验证和Windows用户名问题,.net-core,windows-authentication,.net Core,Windows Authentication,我正在开发ASP.NETCore2.2MVC应用程序。使用windows身份验证对用户进行身份验证,我希望在成功登录后在我的主页中显示登录的用户 我如何使用以下函数/方法来获取用户名,该用户名在调试模式下正常工作 但是当我在IIS中托管时,我没有得到用户名,而是得到了 ApplicationPoolname,Machinename ViewBag.username = Environment.UserName; ViewBag.username = Environm

我正在开发ASP.NETCore2.2MVC应用程序。使用windows身份验证对用户进行身份验证,我希望在成功登录后在我的主页中显示登录的用户

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

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

ApplicationPoolname,Machinename

       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和论坛的所有文档中挖掘了更多信息,但还没有解决方案

已检查以下线程

如果有人能给我一个正确的解决方案,我将不胜感激。

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