Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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
C# 如何在asp.net中获取当前用户?_C#_Asp.net_Authentication_Iis 7.5 - Fatal编程技术网

C# 如何在asp.net中获取当前用户?

C# 如何在asp.net中获取当前用户?,c#,asp.net,authentication,iis-7.5,C#,Asp.net,Authentication,Iis 7.5,我在这里找了更多的时间。当我在本地测试时,它正在工作,示例获取当前用户JoinHenry-ABC\JoinHenry-ABC\JoinHenry,但当在远程服务器中发布时,它不工作,获取DefaultAppPool--IIS APPPOOL\DefaultAppPool。我不知道如何修复它,我尝试用更多的例子来解决这个问题 string test1 = Environment.UserName; string test2 = User.Identity.Name; string test3

我在这里找了更多的时间。当我在本地测试时,它正在工作,示例获取当前用户
JoinHenry-ABC\JoinHenry-ABC\JoinHenry
,但当在远程服务器中发布时,它不工作,获取
DefaultAppPool--IIS APPPOOL\DefaultAppPool
。我不知道如何修复它,我尝试用更多的例子来解决这个问题

 string test1 = Environment.UserName;
 string test2 = User.Identity.Name;
 string test3 = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
 string current = test1  + " - " +  test2  + " - " + test3 ; 
我尝试在web.config中添加
。并在IIS服务器中设置匿名身份验证=禁用,窗口身份验证=启用,并在
Identity=ApplicationPoolIdentity
处更改DefaultAppPool设置。但它不起作用。
对此给出建议

如果要获取登录用户,请使用
HttpContext.Current.User

这与使用
User
直接获取用户当前登录窗口,而不是登录网页没有什么不同。