[英]How to find out the name of currently logged in user in ASP.NET?
我有一个运行在计算机1上的ASP.NET应用程序。
当用户从计算机2访问该页面时,我想找出用户名,以此用户名登录计算机2。
我尝试使用
Request.LogonUserIdentity.Name
Page.User.Identity.Name
((WindowsIdentity)HttpContext.Current.User.Identity).Name
((WindowsIdentity)HttpContext.Current.User.Identity).User
Request.LogonUserIdentity.User
但这不起作用。
Request.LogonUserIdentity.Name
返回NT AUTHORITY\\IUSR
, Request.LogonUserIdentity.User
- S-1-5-17
,所有其他-空字符串。 NT AUTHORITY\\IUSR
是运行Web应用程序的计算机上的用户,而不是客户端计算机上的用户。
在web.config
我使用禁用了模拟
<authentication mode="Windows"/>
<identity impersonate="false"/>
为了获得访问网页的用户的用户名,我该怎么办?
您必须将IIS中的身份验证设置为Windows身份验证(并可能禁用所有其他身份验证):
去:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.