简体   繁体   中英

How to set the bypasslist in .NET CORE 2 Application?

I need to add the list of sites on my API application, in Asp Net would be in the 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>  

How can I add these proxy bypass address in ASP NET CORE API ?

You shoud be able to whitelist websites through CORS, using the following on Startup 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();
}

Hope you'll find this useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM