Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get informaion about the user from its http request

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?

  • I use REMOTE_USER , LOGON_USER , AUTH_USER to get the account name but it doesn't contain any data also

.

like image 648
Anyname Donotcare Avatar asked Feb 25 '23 06:02

Anyname Donotcare


2 Answers

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

like image 96
santosh singh Avatar answered Feb 26 '23 20:02

santosh singh


try this

System.Web.HttpContext.Current.Request.UserHostName;
System.Web.HttpContext.Current.Request.UserHostAddress;
like image 33
Maged Samaan Avatar answered Feb 26 '23 19:02

Maged Samaan