Wednesday, July 29, 2015

IP address of the user who is browsing my website

any times there’s a query to get the IP Address of the client machine from which the user visited the website. Hence I decided to post thismethod .
The following method gets the IP address of the machine from which the client visited the website.
 public string GetClientIP()
    {


        string IPAddress = string.Empty;
        string SearchName = string.Empty;

        String strHostName = HttpContext.Current.Request.UserHostAddress.ToString();

        IPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();


        return IPAddress;
    }

No comments: