title: How to enable CORS in Asp.Net Core 3.0 WebAPI
body: <p>I want to enable CORS with Asp.Net Core 3.0 API project. This is the basic generated Asp.Net Core Api template. Everything is default from the template, except I added CORS settings from the documentation</p>
  
  <pre><code>public class Startup
   {
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddControllers();
          services.AddCors(opt =&gt;
          {
              var origins = Configuration
                  .GetSection("AllowedHosts")
                  .Get&lt;string[]&gt;();
  
              opt.AddPolicy("CorsPolicy", builder =&gt; builder
                      .WithOrigins(origins)
                      .AllowAnyMethod()
                      .AllowAnyHeader()
                      .Build());
          });
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
  
          app.UseHttpsRedirection();
  
          app.UseRouting();
  
          app.UseCors("CorsPolicy");
          app.UseAuthorization();
  
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapControllers();
          });
      }
  }
  </code></pre>
  
  <p>What should I set up for getting corret CORS in .net core web api?
  Allowed host is :
  <a href="https://i.stack.imgur.com/M91gT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M91gT.png" alt="enter image description here"></a></p>