加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 22:51:29 所属栏目:百科 来源:网络整理
导读:我需要在我的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 /co
我需要在我的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();
}

希望你会发现这很有用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读