ASP.NET: fetch IP Address information RRS feed

  • Question

  • hello Team,

    In my ASP.Net 4 Internet application, the IP address information requires to be fetched of the devices (desktop/laptop/mobile).

    Can you help confirm and provide some alternatives to capture this information?

    1. Following is the code snippet to fetch the IPv4 information

    string VisitorsIPAddr = string.Empty;
    	if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
    		VisitorsIPAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
    	else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
    		VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;
    2. Can you confirm if using the server variable "REMOTE_ADDR" will resolve the issue for accessing the IP Address for all clients? What will be the limitations or use-cases which this might skip. Or how should I provision this.

    3. How can I fetch the IPv6 Address for the visitors to the website? The Server ipconfig command displayed IPv4 & IPv6 address.

    4. For the client, with both IPv4 & IPv6 address, which IP will be used for the request and therefore which IP should be used to save the information?

    Also, it will be good to get some documentation link to resolve these.


    • Moved by Sabah ShariqMVP Friday, June 9, 2017 10:06 AM Moved From Visual C#
    Friday, June 9, 2017 7:54 AM

All replies

  • Hi MSDN_Geek,

    This is Visual C# forum. As your issue is related to Web, please ask your question into ASP.Net forum for getting quick response. I am moving your thread to off-topic.

    Your understanding and cooperation will be grateful.

    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Friday, June 9, 2017 10:06 AM
  • Already the questions relating to the Web have been asked in the forum!. can you help re-categorize/forward this in the correct forum? Perhaps web development / Visual Studio Web?


    Friday, June 9, 2017 11:18 AM