如何在.NET CORE 2应用程序中设置bypasslist?

4
我需要在我的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中添加这些代理绕过地址?
1个回答

1

您应该能够通过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();
}

希望您会觉得这很有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接