繁体   English   中英

如何找出ASP.NET中当前登录用户的名称?

[英]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\\IUSRRequest.LogonUserIdentity.User - S-1-5-17 ,所有其他-空字符串。 NT AUTHORITY\\IUSR是运行Web应用程序的计算机上的用户,而不是客户端计算机上的用户。

web.config我使用禁用了模拟

<authentication mode="Windows"/>
<identity impersonate="false"/>

为了获得访问网页的用户的用户名,我该怎么办?

您必须将IIS中的身份验证设置为Windows身份验证(并可能禁用所有其他身份验证):

在此处输入图片说明

去:

  • 网站
  • IIS-身份验证
  • 根据您的意愿进行编辑

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM