1

I am attempting to obtain similar information as found on https://www.whatismybrowser.com. I specifically am looking for the external and local IP addresses. This is the .NET Core code that I am using to obtain this information:

HomeController.cs

ViewData["RemoteIp"] = HttpContext.Connection.RemoteIpAddress.ToString();
ViewData["LocalIp"] = HttpContext.Connection.LocalIpAddress.ToString();

Startup.cs

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseForwardedHeaders(new ForwardedHeadersOptions
        {
            ForwardedHeaders = ForwardedHeaders.XForwardedFor
        });

The application lives behind an F5, so it results with a remote IP with my machine IP and a local IP that is the loopback IP address. The DNS entry is available externally, which then goes through the F5, then points to the server running the application.

Ideally, I would like the remote IP to return the external IP as done in the ipify API.

I've reviewed the following SO threads already in attempt for a solution: How to get Client IP address in ASP.NET Core 2.1

I've also reviewed the MSDN documentation as found here: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.1

One other factor: I plan on reusing this concept across multiple devices, including iOS, Android, and Windows platforms. I haven't decided on a framework, but I've entertained the ideas of Xamarin and PhoneGap.

  • Did you enable *Insert X-Forwarded-For* at the *HTTP Profile* associated to your *Virtual Server* ? – Eugène Adell Dec 03 '18 at 10:30
  • Have you found a solution for this? All the help I found relates to the full .NET framework – AntLaC Dec 14 '18 at 17:45
  • @AntLaC Yes, we found a solution to this. It was unrelated to the code. The code functions correctly. The actual issue was that the X-Forwarded IP address was transformed to point to a different IP address once it hit the server. Between our firewall and server, though, the X-Forwarded IP was correct. We had to reconfigure server settings to prevent the X-Forwarded IP to be transformed. – Jennifer Bartolome Jan 09 '19 at 21:59
  • @EugèneAdell Yes, we did. See my previous comment regarding the actual issue. Thank you. – Jennifer Bartolome Jan 09 '19 at 22:00

0 Answers0