SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast bzforum's Avatar
    Join Date
    Mar 2012
    Location
    India
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    Code:
    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();
    }
    else
    {
                trueip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    }
    Hope this comes handy

  2. #2
    Non-Member
    Join Date
    Oct 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hi

    Quote Originally Posted by bzforum View Post
    Here is the code for displaying the IP Address of your visitor in ASP.NET

    Code:
    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();
    }
    else
    {
                trueip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    }
    Hope this comes handy
    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...
    regards
    Andy
    <snip />
    Last edited by SpacePhoenix; Nov 2, 2012 at 13:57. Reason: removed fake signature

  3. #3
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Forgot to declare "ip"?
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  4. #4
    SitePoint Enthusiast bzforum's Avatar
    Join Date
    Mar 2012
    Location
    India
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for the late reply guys I was busy...

    The ip is a String Type

    just add this before

    Code:
    sting ip;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •