question

Desbrina avatar image
0 Votes"
Desbrina asked TimonYang-MSFT commented

c# Connect via a proxy

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

With

On Corp it shows Error 400

Off Corp it shows Can't find host

Without

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
dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Desbrina
What is a corp network?
Do you mean this?
corpnetworking
If so, I'm afraid you need to ask them for help, because we can't use their services for testing.

0 Votes 0 ·

0 Answers