Friday, 19 October 2012

find ip address in asp.net c#


Step 1: Finding Visitor's IP Address in Asp.net, C# Code.

You can use following Code to find Visitors IP Address in Asp.net


string VisitorsIPAddr = string.Empty;//Users IP Address.                if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null){//To get the IP address of the machine and not the proxyVisitorsIPAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();}else if (HttpContext.Current.Request.UserHostAddress.Length != 0){VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;}

No comments:

Post a Comment