我需要在我的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将网站列入白名单,使用以下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();
}
希望你会发现这很有用.