0

I have an Angular app that makes requests to a .NET 4.6.2 Web MVC Controller and the code inside the controller makes a requests with a HttpClient to a .NET Core 3.1 API. All apps is hosted in Azure.

So Angular -> .NET 4.6.2 -> .NET Core 3.1 API.

I want to get the originating client IP in the .NET Core app. Requests that are sent directly from the client to .NET Core app is working fine by reading HttpContext.Connection.RemoteIpAddress after I added the environment variable ASPNETCORE_FORWARDEDHEADERS_ENABLED = true in Azure. But not when going through the .NET 4.6.2 app, in that case the IP is an Azure IP and not the clients IP.

What is the best way to forward the client ip information from .NET 4.6.2 app to the NET Core 3.1 app?

1
  • 1
    You'll need to store that IP and pass it along. Generally this would be done via an additional HTTP header. Commented Oct 27, 2020 at 16:04

1 Answer 1

1

You could read the client's IP address in the .NET 4.6.2 app and send it to the .NET Core app using custom HTTP header (something like X-CLIENTIP). On the .NET Core app first try to get the custom header. If it doesn't exist (which means the call came directly from the client), read it from HttpContext.Connection.RemoteIpAddress

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.