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

问题描述 投票:4回答:1

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

c# web-config asp.net-core-webapi
1个回答
1
投票

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

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();
}

希望你会发现这很有用。

© www.soinside.com 2019 - 2024. All rights reserved.