Get User IP Address Based On Client Location

This code is useful only for C#.net tech. How to know the location of the end user. Identify the network address by HTTP_X_FORWARDED_FOR / REMOTE_ADDR. This is browser enable server variable. 

Use the code below to get the HTTP_X_FORWARDED_FOR  or REMOTE_ADDR Variable value in your C#.net at Page load event.

private string GetUserIP() {
    string ipaddress = string.Empty;
    try {
        string ipList = this.Page.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (!string.IsNullOrEmpty(ipList) && !ipList.Contains("::")) {
            ipaddress = ipList.Split(',')[0];
        } else {
            ipaddress = this.Page.Request.ServerVariables["REMOTE_ADDR"];
        }
    } catch (Exception ex) {
        // Log your message
    }
    return ipaddress;
}

Once you get the value, you can compare the value with your Network IP address database. You can get your Network IP address list from your Network engineering team.

I hope that will work for you. Happy Coding...