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

DP_*_*DP_ 5 .net c# 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"/>
Run Code Online (Sandbox Code Playgroud)

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

Pat*_*man 5

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

在此处输入图片说明

去:

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