c# Connect via a proxy

Desbrina 1 Reputation point

Our system when we are on the corporate network connects through a proxy, I'm struggling to get my application to connect

The only way i've been able to get it to connect is without a proxy, off our corp network. The proxy url is a internal url, only available on the corp network

I've tried setting a proxy up, PROXY URL replaced by what's in the computers proxy settings

public class ProxySupportedHttpClientFactory : HttpClientFactory
    protected override HttpMessageHandler CreateHandler(CreateHttpClientArgs args)
        var proxyAddress = "PROXY URL";
        var proxy = new WebProxy(proxyAddress, true, null, CredentialCache.DefaultNetworkCredentials);
        var webRequestHandler = new HttpClientHandler()
            UseProxy = true,
            Proxy = proxy,
            UseCookies = false
        return webRequestHandler;

With the proxy set in code I get the following behaviour


On Corp it shows Error 400

Off Corp it shows Can't find host


On Corp it shows the proxy login prompt

Off Corp then it works as expected

How do I make it so that it mirrors what happens with web browsers etc. That when its on the corp network, it goes through the proxy, when its off it doesn't

The computers proxy settings are set to

automatically detect = on
setup script = on
script address = set to internal url
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,233 questions
{count} votes