如何找出ASP.NET中当前登录用户的名称? [英] How to find out the name of currently logged in user in ASP.NET?
问题描述
我有一个运行在计算机1上的ASP.NET应用程序.
I have an ASP.NET application, which runs on machine 1.
当用户从计算机2访问该页面时,我想找出他或她在计算机2上登录所使用的用户名.
When a user access that page from machine 2, I want to find out the user name, under which he or she is logged in on machine 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应用程序的计算机上的用户,而不是客户端计算机上的用户.
Request.LogonUserIdentity.Name
returns NT AUTHORITY\IUSR
, Request.LogonUserIdentity.User
- S-1-5-17
, all others - empty strings. NT AUTHORITY\IUSR
is the user on the machine, on which the web application runs, not the user on the client machine.
在 web.config
中,我使用
<authentication mode="Windows"/>
<identity impersonate="false"/>
如何获取访问网页的用户的用户名?
What can I do in order to get the user name of the user, who accesses the web page?
推荐答案
您必须将IIS中的身份验证设置为Windows身份验证(并可能禁用所有其他身份验证):
You have to set the authentication in IIS to Windows Authentication (and probably disable all others):
转到:
- 网站
- IIS-身份验证
- 根据您的意愿进行编辑
这篇关于如何找出ASP.NET中当前登录用户的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!