title: Allow Cors Origin in ASP.NET Core
body: <p>I am using Microsoft.ApsNetCore.Cors 2.2</p>
  <blockquote>
  <p>&quot;Access to XMLHttpRequest at 'exampleapi.local' from origin 'example.local' has been blocked by CORS policy:<br />
  No 'Access-Control-Allow-Origin' header is present on the requested resource.&quot;</p>
  </blockquote>
  <p>I set the settings with this:</p>
  <pre class="lang-cs prettyprint-override"><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddCors(options =&gt;
      {
          options.AddPolicy(&quot;AllowSpecificOrigin&quot;,
                  builder =&gt;
                  {
                      builder                            
                      .AllowAnyOrigin()
                      .AllowAnyMethod()
                      .AllowAnyHeader();
                  });
      });
  
      services.Configure&lt;TokenSettings&gt;(this.Configuration.GetSection(&quot;Tokens&quot;));
      services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
          .AddJwtBearer(opt =&gt;
          {
              opt.TokenValidationParameters = new TokenValidationParameters
              {
                  ValidateIssuer = true,
                  ValidateAudience = true,
                  ValidateLifetime = true,
                  ValidateIssuerSigningKey = true,
                  ValidIssuer = Configuration[&quot;Tokens:Issuer&quot;],
                  ValidAudience = Configuration[&quot;Tokens:Audience&quot;],
                  IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration[&quot;Tokens:SecurityKey&quot;]))
              };
          });
  
      services.AddMvc();
      services.Configure&lt;LdapConfig&gt;(Configuration.GetSection(&quot;ldap&quot;));
      services.AddScoped&lt;ILdapAuthenticationService, LdapAuthenticationService&gt;();
      services.AddScoped&lt;IUserService, UserService&gt;();
      services.AddScoped&lt;IProjectService, ProjectService&gt;();
      services.AddScoped&lt;IProjectMembersService, ProjectMembersService&gt;();
      services.AddScoped&lt;IJourneyUsersService, JourneyUsersService&gt;();
      services.AddScoped&lt;IProjectRolesService, ProjectRolesService&gt;();
      services.AddScoped&lt;IPmoGuardianService, PmoGuardianService&gt;();
      services.AddScoped&lt;IHolidaysService, HolidaysService&gt;();
      services.AddScoped&lt;IMailService, MailService&gt;();
      services.AddScoped&lt;INotificationsService, NotificationsService&gt;();
      services.AddScoped&lt;INotificationUsersService, NotificationUsersService&gt;();
      services.Configure&lt;AWSConfigSes&gt;(Configuration.GetSection(&quot;AWSSmtp&quot;));
      services.AddDbContext&lt;JourneyContext&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString(&quot;JourneyConnection&quot;)));
      services.AddDbContext&lt;TSMContext&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString(&quot;TSMConnection&quot;)));
      services.AddDbContext&lt;PmoGuardianContext&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString(&quot;PmoGuardianConnection&quot;)));
  
  }
  
  public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMailService mail, INotificationsService not)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
      }
  
      Recurrence recurrency = Recurrence.GetInstance(not);
      //new TSMClockService(mail);
  
      app.UseCors(&quot;AllowSpecificOrigin&quot;);
      app.UseAuthentication();
  
      app.UseMvc();
  }
  
  [Produces(&quot;application/json&quot;)]
  [Route(&quot;api/Mail&quot;)]
  [EnableCors(&quot;AllowSpecificOrigin&quot;)]
  </code></pre>
  <p>But It doesn't work, always I got the same error</p>