如何在 .NET CORE 2 应用程序中设置旁路列表?
How to set the bypasslist in .NET CORE 2 Application?
我需要在我的 API 应用程序中添加站点列表,在 Asp 中,网络将在 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 将网站列入白名单,在启动时使用以下命令 class:
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();
}
希望你会发现这有用。
我需要在我的 API 应用程序中添加站点列表,在 Asp 中,网络将在 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 将网站列入白名单,在启动时使用以下命令 class:
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();
}
希望你会发现这有用。