C# 如何在.NET CORE 2应用程序中设置旁路列表?

C# 如何在.NET CORE 2应用程序中设置旁路列表?,c#,web-config,asp.net-core-webapi,C#,Web Config,Asp.net Core Webapi,我需要在我的API应用程序中添加网站列表,在Asp Net中,该列表将位于web.config中: <configuration> <system.net> <defaultProxy> <bypasslist> <add address="[a-z]+\.contoso\.com$" /> <add address="192\.168\.\d{1,3}\

我需要在我的API应用程序中添加网站列表,在Asp Net中,该列表将位于web.config中:

<configuration>  
  <system.net>  
    <defaultProxy>  
      <bypasslist>  
        <add address="[a-z]+\.contoso\.com$" />  
        <add address="192\.168\.\d{1,3}\.\d{1,3}" />  
      </bypasslist>  
    </defaultProxy>  
  </system.net>  
</configuration>  


如何在ASP NET CORE API中添加这些代理绕过地址?

您应该能够使用以下启动时类通过CORS将网站列入白名单:

public void ConfigureServices(IServiceCollection services)
{
  ...
  services.AddCors(options =>{
     options.AddPolicy("MyAppCorsPolicy", x => {
        x.WithOrigin("*.contoso.com", "*.example.com", ...);
        x.AllowAnyHeader();
        x.WithMethods("GET", "POST", "PUT", "PATCH", ...);
     });
  });
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
  ...
  app.UseCors("MyAppCorsPolicy");
  app.UseMvc();
}
希望你会觉得这很有用