Mahdi_Nine
Mahdi_Nine

Reputation: 14751

How to get client's computer name

I saw this question in another post but the solution did not work correctly. I use:

System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST")).HostName

This worked correctly on localhost but on server it has problems and returns an empty string. Any idea?

Upvotes: 3

Views: 16992

Answers (3)

Ramon Araujo
Ramon Araujo

Reputation: 1738

Take into account that HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST") will return the name of the host making the request, not the address.

Try doing System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST")).HostName instead.

You can find a list of the Server Variables at Microsoft's MSDN website.

Upvotes: 1

Massimiliano Mirelli
Massimiliano Mirelli

Reputation: 21

I find out that already in VS2010 "GetHostByAddress" is deprecated. Instead, use: System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_HOST"])

Upvotes: 2

suresh pareek
suresh pareek

Reputation: 98

To get client IP address use

HttpContext.Current.Request.UserHostAddress.ToString

or

HttpContext.Current.Request.UserHostName

To get client browser use

HttpContext.Current.Request.Browser.Browser

Upvotes: 0

Related Questions