Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure a proxy in a .Net Core Console App

In previous .Net console applications we can avoid proxy 407 errors by including the following in app.config:

<system.net>
  <defaultProxy useDefaultCredentials="true"/>
</system.net>

.Net Core console app does not have app.config - how can we do the same?

Specifically for an Azure DocumentDB DocumentClient.

like image 901
Shevek Avatar asked Mar 28 '17 13:03

Shevek


1 Answers

It looks like that for now Azure-oriented team didn't implement such feature. Here is a link to recent github issue for Azure AD library, which states that

  • Currently ADAL for .NET doesn’t support WebProxy configuration.
  • Please configure proxy at the system level. Httpclient used by Adal should be able to use it.
  • Production team has planned to add this function in future version, but currently they don’t have estimation time.

As far as one can see, there is no such feature available in Microsoft.Azure.Documents.Client namespace or in Microsoft.Azure.Documents namespace, so for now you have to resolve it on system level. You can probably create a github issue or contact the team on MSDN or by email.

As for general .Net Core app, you can use the HttpClientHandler class' DefaultProxyCredentials property, so the code will be like this:

var handler = new HttpClientHandler { UseDefaultCredentials = true };
using (var client = new HttpClient(handler))
{
    // http call here
}
like image 141
VMAtm Avatar answered Sep 25 '22 14:09

VMAtm