Skip to main content

i4connected Knowledge Base

Configuring ASP.NET Core to work with proxy servers and load balancers

Abstract

Check out this article and learn more details on how to configure ASP.NET Core to work with proxy servers and load balancers.

In the recommended configuration for ASP.NET Core, the app is hosted using IIS/ASP.NET Core Module, Nginx, or Apache. Proxy servers, load balancers, and other network appliances often obscure information about the request before it reaches the app:

  • When HTTPS requests are proxied over HTTP, the original scheme (HTTPS) is lost and must be forwarded in a header.

  • Because an app receives a request from the proxy and not its true source on the Internet or corporate network, the originating client IP address must also be forwarded in a header.

Tip

For more details please also visit this article here.

At the level of i4connected portal, configuring ASP.NET Core to work with proxy servers and load balancers is important in the requests processing, such as redirects, authentication, link generation, policy evaluation, and geolocation.

To enable proxy usage, the following changes need to be performed:

  1. Open the i4connected API folder, identify the web.config file and open it using an editor tool.

  2. Identify the "ASPNETCORE_FORWARDEDHEADERS_ENABLED" setting.

    environmentvariable.jpg
  3. Change the setting to "true" and make sure your changes are saved, before closing the web.config file.

    <environmentVariables>
       <environmentVariable name="ASPNETCORE_FORWARDEDHEADERS_ENABLED" value="true" />
    <environmentVariables>
  4. Next, open the i4connected API folder, identify the appsettings.json file and open it using an editor tool.

  5. The appsettings.json file allows you to control the behavior of the Forwarded Headers Middleware.

    API_appsettings.jpg

    Note

    If no further changes are needed, you can leave the default settings. To add custom settings, please make sure to comment them in, and properly save the file before closing it.

  6. Proceed with the same settings in the appsettings.json file, located in the i4connected Identity folder.

    Identityappsettings.jpg

    Warning

    The Forwarded Headers Middleware settings of the Identity appsettings.json file should coincide with the settings done in the API appsettings.json file.