简体   繁体   中英

Default Proxy ASP.NET Core Web API

I need to configure a default proxy to enable Application Insights. In an ASP.NET Web Api the default proxy can be set in the web.config like below:

  <system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true">
      <proxy proxyaddress="someaddress" bypassonlocal="True" />
    </defaultProxy>
  </system.net>

With this setting AI works fine. Unfortunately I could not find an option to set the proxy in appsettings.json. Is there any possibility to define the default proxy in an ASP.NET Core Web API?

Or do I have to configure the proxy in IIS, when the application is getting hosted with it?

Edit: I am setting the default proxy now like this:

    WebRequest.DefaultWebProxy = new WebProxy(new Uri("someaddress"), true)
    {
        UseDefaultCredentials = true
    };

When getting the proxy with

WebRequest.DefaultWebProxy.GetProxy(new Uri("https://dc.services.visualstudio.com/v2/track"))

it returns the correct proxy.

Strange things happens when Fiddler is running. As soon as Fiddler is running the application is logging successfully to AI. When closing Fiddler the logging breaks again.

Has anyone an idea?

Do you mean you want to configure HttpClient proxy globally?

If so, I am afraid it is impossible. You may consider creating an encapsulate class with accepting Proxy configuration and return a HttpClient, you could load the configuration from appsettings.json or anywhere

也许您的流量正在通过 Fiddler 代理,因此当 Fiddler 关闭时,您可以连接到其他服务。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM