Reputation: 14751
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
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
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
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