@Gareth Wynn - Welcome to Microsoft Q&A and thanks for reaching out to us .
The WebProxy class in .NET specifies a Uri as the proxy host, but Azure Firewall configures separate HTTP and HTTPS ports. You are correct that WebProxy only supports specifying the http address and that doesn't seem to work with Azure Firewall. One way to work around this limitation is to use a custom implementation of the IWebProxy interface. You can create a class that implements the IWebProxy interface and use it to specify the proxy settings for your .NET app.
Please see below for a sample implementation of the IWebProxy interface that you can use as a starting point:
public class AzureFirewallWebProxy : IWebProxy { private readonly Uri _proxyUri; public AzureFirewallWebProxy(Uri proxyUri) { _proxyUri = proxyUri; } public ICredentials Credentials { get; set; } public Uri GetProxy(Uri destination) { return _proxyUri; } public bool IsBypassed(Uri host) { return false; } }
You can then use this class to configure the proxy settings for your HttpClient:
var proxyUri = new Uri("http://10.10.10.132:8080");
var proxy = new AzureFirewallWebProxy(proxyUri);
var httpClientHandler = new HttpClientHandler
{
Proxy = proxy,
UseProxy = true
};
var httpClient = new HttpClient(httpClientHandler);
This should allow you to use Azure Firewall in explicit proxy mode with your .NET app. Let me know if you have any further questions or concerns.
Hope this helps. and please feel free to reach out if you have any further questions.
Please don't forget to "Accept as Answer" and click "Yes" if the above response is helpful, so it can be beneficial to the community.