如何获取我已登录的计算机的帐户名 [英] How to Get Account name of Machine I am logged In

查看:67
本文介绍了如何获取我已登录的计算机的帐户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何获得我登录的帐户信息.就像如果使用stalin_king登录到一台计算机上一样,那么如何通过ASP.Net获得该信息.

我正在使用WindowsIdentity.GetCurrent().Name.ToString().Trim();,但这是为服务器帐户名提供所需的名称,就像我想要打开此站点的计算机的用户名一样.

任何想法.

Hi,

How can I get the account information I am logged in. Like if I am logged in with stalin_king into one machine, then how can I get that thorugh ASP.Net.

I am using WindowsIdentity.GetCurrent().Name.ToString().Trim();, but this is giving the server account name where as I want the user name of the machine where I open this site.

Any ideas.

推荐答案

这取决于您将Asp.Net身份验证设置为哪种模式.这是一篇简短介绍选项的文章

http://www.4guysfromrolla.com/articles/031204-1.aspx [ ^ ]

现在,假设您要使用"Windows身份验证",因为您要获取连接到该站点的用户的帐户名.在这种情况下,您需要确保在web.config中设置了此模式,并且将IIS站点设置为使用集成身份验证"

然后,您可以使用类似的方法来获取Windows主体对象

//获取经过身份验证的用户的身份
WindowsPrincipal winPrincipal =(WindowsPrincipal)HttpContext.Current.User;

只需访问HttpContext.Current.User对象,您就可以得到想要的结果

进一步阅读

http://msdn.microsoft.com/en-us/library/ff647076.aspx [ ^ ]
It depends what mode you have your Asp.Net authentication set to. Here''s an article which briefly describes the options

http://www.4guysfromrolla.com/articles/031204-1.aspx[^]

Now, I''m assuming you want to work with ''Windows Authentication'' since you want to get the account name of the user connecting to the site. In which case, you''ll need to make sure this mode is set in your web.config and that you have your IIS site set to use ''Integrated Authentication''

You could then use something like this to get the Windows Principal object

// Obtain the authenticated user''s Identity
WindowsPrincipal winPrincipal = (WindowsPrincipal)HttpContext.Current.User;

Just accessing the HttpContext.Current.User object should give you what you want though

Further reading

http://msdn.microsoft.com/en-us/library/ff647076.aspx[^]


您可以通过Environment.MachineName


获取计算机的名称,我不确定您的应用程序是用于Internet还是Intranet.
如果要用于Internet,恐怕是不可能的.或者我应该说ASP.Net没有做到这一点的方法,您总是可以编写某种ActiveX控件来做到这一点.

现在是Intranet的东西.您可以尝试以下一种方法:

Well, I am not sure if you application is for Internet or Intranet.
If it is intended for internet, I am afraid that would not be possible. Or I should say ASP.Net does not have a way to do it, you can always write some kind of ActiveX control to do this.

Now comes the intranet thingie. You can try this one:

Dim host As System.Net.IPHostEntry
host = System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST"))
string strComputerName = host.HostName


这篇关于如何获取我已登录的计算机的帐户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆