我的IP地址,但由于某些原因,我可以得到正确的名称解析,显示本地计算机名称。我尝试一些东西,他们都正显示出服务器主机名?
ipadd = HttpContext.Current.Request.ServerVariables [REMOTE_ADDR]; ip地址MYIP = IPAddress.Parse(ipadd); IPHostEntry GetIPHost = Dns.GetHostEntry(MYIP); // userhostname = System.Environment.MachineName; // userhostname = Dns.GetHostName(); //解决ServerHostName没有电脑 // userhostname = HttpContext.Current.Request.UserHostName; // userhostname = HttpContext.Current.Request.UserAgent; userhostname = GetIPHost.HostName;有关用户名,我特林使用
nametext = WindowsIdentity.GetCurrent()名称。//服务器部署时,显示服务器名称//当debuging和localY运行显示登录正确的当前用户// nametext = HttpContext.Current.Request.ServerVariables [LOGON_USER];//不返回任何东西我交换身份验证和没有结果。
<身份验证模式=表格><身份验证模式=窗口>解决方案
使用Htt$p$pquest.UserHostAddress和Htt$p$pquest.UserHostName客户端IP和机器名。
假设你有身份验证正确配置,你可以从IIdentity.Name.
在一个 页面的上下文 ,则可以使用 Request.UserHostAddress , Request.UserHostName 和 User.Identity.Name 。
I have the IP address, but for some reason I can get the name resolve correctly to show local computer name. I try few things and all of them is showing the server hostname?
ipadd = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; IPAddress myIP = IPAddress.Parse(ipadd); IPHostEntry GetIPHost = Dns.GetHostEntry(myIP); //userhostname = System.Environment.MachineName; //userhostname = Dns.GetHostName(); //Resolve ServerHostName not computer //userhostname = HttpContext.Current.Request.UserHostName; //userhostname = HttpContext.Current.Request.UserAgent; userhostname = GetIPHost.HostName;For user name I am tring to use
nametext = WindowsIdentity.GetCurrent().Name; //Shows server name when deployed on server //when debuging and running localy shows correctly current user logged in //nametext = HttpContext.Current.Request.ServerVariables["LOGON_USER"]; // not returning anythingI switched authentication and no results
<authentication mode="Forms"> <authentication mode="Windows">解决方案
Use HttpRequest.UserHostAddress and HttpRequest.UserHostName for client IP and machine name.
Assuming you have authentication configured correctly, you can get the client user from IIdentity.Name.
In the context of a Page, you can use Request.UserHostAddress, Request.UserHostName and User.Identity.Name.
更多推荐
我怎样才能获取客户端的主机名,本地计算机名和用户名在C#和asp.net
发布评论