Displaying the IP address of your visitor in ASP.NET

Here is the code for displaying the IP Address of your visitor in ASP.NET

string trueip = string.Empty;
ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
            string[] iprange = ip.Split(',');
            trueip = iprange[0].Trim();
            trueip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

Hope this comes handy :wink:

thanks for the replay in advance but i need to know what data tye u have selected for ip… u have declared string as trueip … but what type of data came in ip…
<snip />

Forgot to declare “ip”? :wink:

Sorry for the late reply guys I was busy…

The ip is a String Type

just add this before

sting ip;