2 ranistar ranistar 于 2016.02.16 13:16 提问

如何取到用户机器的机器名和域名?

网站发布在IIS上面,用户机器名一般格式为: 域名/机器名。
以下方法均没有成功:
string s1 = "User:" + filterContext.HttpContext.Request.LogonUserIdentity.User.ToString() + "\r\n";
string s2 = "AuthenticationType:" + filterContext.HttpContext.Request.LogonUserIdentity.AuthenticationType.ToString() + "\r\n";
string s3 = "Name:" + filterContext.HttpContext.Request.LogonUserIdentity.Name.ToString() + "\r\n";
string s4 = "IsGuest:" + filterContext.HttpContext.Request.LogonUserIdentity.IsGuest.ToString() + "\r\n";
string s5 = "Owner:" + filterContext.HttpContext.Request.LogonUserIdentity.Owner.ToString() + "\r\n";
string s6 = "LoginUser:" + HttpContext.Current.User.Identity.Name + "\r\n";
string s7 = "ComputerName:" + Dns.GetHostName() + "\r\n";
string s8 = "DomainName:" + System.Environment.UserDomainName.ToString() + "\r\n";
string s9 = "UserName:" + System.Environment.UserName.ToString() + "\r\n";
string s10 = "DomainName2:" + Dns.GetHostEntry(Dns.GetHostName()) + "\r\n";
string s11 = "DomainName3:" + IPGlobalProperties.GetIPGlobalProperties().DomainName + "\r\n";
string s12 = "DomainComputerName(host):" + IPGlobalProperties.GetIPGlobalProperties().HostName + "\r\n";
string s13 = "DomainComputerName1:" + filterContext.HttpContext.Request.ServerVariables.Get("remote_addr").ToString() + "\r\n";
string s14 = "DomainComputerName2:" + Dns.GetHostEntry(strIpAddr).ToString() + "\r\n";
string s15 = Dns.GetHostEntry(strIpAddr).Aliases.ToString() + "\r\n";
string s16 = Dns.GetHostEntry(strIpAddr).HostName.ToString() + "\r\n";


2个回答

showbo
showbo   Ds   Rxr 2016.02.16 14:17

b/s客户端机器名获取不到。。
如果你自己玩玩,可以配置ie浏览器权限,用js+acx来做,自己搜

Mr_dsw
Mr_dsw   Ds   Rxr 2016.02.16 22:21

这样行么:
获取服务器电脑名: Page.Server.ManchineName
获取用户信息: Page.User
获取客户端电脑名:Page.Request.UserHostName
获取客户端电脑IP: Page.Request.UserHostAddress
2. 在网络编程中的通用方法:
获取当前电脑名: static System.Net.Dns.GetHostName()
根据电脑名取出全部IP地址: static System.Net.Dns.Resolve(电脑名).AddressList
也可根据IP地址取出电脑名: static System.Net.Dns.Resolve(IP地址).HostName
3. 系统环境类的通用属性:

ranistar
ranistar page.user取到的是form的吧。。
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!