ASP.NET Framework - Use the default proxy for the HttpClient calls

If you want to use the default proxy (the one you set up for you PC in Settings > Network & Internet > Proxy on Windows), with the default credentials, for the HttpClient calls inside an ASP.NET Framework web application, you can follow two possible ways:

  1. You can set up the proxy on the HttpClientHandler used for the HttpClient:
    1var httpClientHandler = new HttpClientHandler();
    2// ...
    3httpClientHandler.UseProxy = true;
    4httpClientHandler.Proxy = new System.Net.WebProxy(Address: "proxy_address", BypassOnLocal: false); // Set BypassOnLocal as you need
    This solution can be good if you need to use proxy only for some calls and not globally.
  2. If you want to set up the default proxy globally, so each HttpClient created in the web application will use the default proxy, you need to add the following configuration to the Web.config of the web application:
    1<system.net>
    2  <defaultProxy useDefaultCredentials="true" enabled="true" />
    3</system.net>

Links