Get user information from your http request

IN:

I want to ask how to get the name Computer name and account name of the user who created the http request on my website. According to his request.

When I search, I find this:

  • REMOTE_HOST

    The host name that creates the request. If the server does not have this information, it will set REMOTE_ADDR and leave it blank.

    Why can a server never contain a host name? and how can i fix this?

  • I use REMOTE_USER , LOGON_USER , AUTH_USER to get the account name but it also does not contain any data.

.

+4
source share
2 answers

You can use the Request.ServerVariables object, for example

 // 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 the computer name, try

 string computer_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName; Response.Write(computer_name); 

EDIT II

// Get information about the client machine

 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 options, check the following link

IIS Server Variables

+5
source

try it

 System.Web.HttpContext.Current.Request.UserHostName; System.Web.HttpContext.Current.Request.UserHostAddress; 
+3
source

All Articles