我有IP地址,但出於某種原因,我可以正確解析名稱以顯示本地計算機名稱。我嘗試了幾件事,他們都顯示服務器主機名?如何在c#和asp.net中獲取客戶端主機名,本地計算機名稱和用戶名
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;
對於用戶名,我特林使用
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 anything
我交換身份驗證和沒有結果
<authentication mode="Forms">
<authentication mode="Windows">
是互聯網上或Intranet上的這個運行?如果它在網絡上運行,出於安全原因,您可能無法訪問諸如主機名和Windows用戶名等詳細信息。我從來沒有嘗試過,但似乎這些事情可能會受到保護/不可用。 – Jim 2012-07-10 18:19:51
這是在內部網上。我認爲問題是在IIS上的身份驗證模式中,我現在已經在IIS 7中啓用匿名身份驗證。我正在考慮使用JavaScript函數來檢索此信息。 – laspalmos 2012-07-10 18:29:27
您需要打開Windows身份驗證才能正常工作,我相信。 – Jim 2012-07-10 18:46:44