≡ Menu

How to get site visitor Api in asp.net

How to get IP Host Address of remote Client

// To get IP of the client meachine
// There is two methods to obtain IP address

// Method 1
//     Gets the IP host address of the remote client.
// Returns:
//     The IP address of the remote client.
string ipMethod1 = Request.UserHostAddress; // HttpContext.Current.Request.UserHostAddress;

//Methord 2
//Request.ServerVariables is a Name Value Collection
//     Gets a collection of Web server variables.
// Returns:
//     A System.Collections.Specialized.NameValueCollection of server variables.
string ipMethod2 = Request.ServerVariables["REMOTE_ADDR"]; //HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

Comments on this entry are closed.