Q:
I want to ask about how to get the Computer name and the account name of the user who making an http request
to my web site.according to his request.
When i search i find that:
REMOTE_HOST
The name of the host that is making the request. If the server does not have this information, it will set REMOTE_ADDR and leave this empty.
Why the server may never contain the host name? and how can i fix this?
REMOTE_USER
, LOGON_USER
,
AUTH_USER
to get the account name
but it doesn't contain any data also.
You can use the Request.ServerVariables object like
// will return the host name making the request
string s = Request.ServerVariables["REMOTE_HOST"]
// will return the computer name
string s = Request.ServerVariables["SERVER_NAME"]
EDIT
If you want to get computer name then try following
string computer_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName;
Response.Write(computer_name);
EDIT II
//Retrieving Client Machine details
System.Net.IPAddress[] strClientIPAddress = System.Net.Dns.GetHostAddresses(Environment.MachineName);
string strClientMachineName = Environment.MachineName.ToString().Trim();
string strClientUserName = Environment.UserName.ToString().Trim();
string strClientDomainName = Environment.UserDomainName.ToString().Trim();
string strClientOSVersion = Environment.OSVersion.ToString().Trim();
For more server variables check out the following link
IIS Server Variables
try this
System.Web.HttpContext.Current.Request.UserHostName;
System.Web.HttpContext.Current.Request.UserHostAddress;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With