title: React+ASP.NET.Core : No 'Access-Control-Allow-Origin' header is present on the requested resource
body: <p>Actually this is not a <strong>duplication</strong> post,I know a part of the title asked many times in <a href="http://stackoverflow.com">stackoverflow</a> community, I read all posts, and answers, but I think my problem and technologies which I used are different.</p>
  
  <p>First of all I should mention <code>ASP.NET Core WEB/API</code> is my back-end-app and <code>Reactjs</code> is my front Application.</p>
  
  <p>I read about <code>CORS</code> and I found out I must enable <code>CORS</code> on <code>ASP.NET</code> App and put  <code>'Access-Control-Allow-Origin':'*'</code> on my request's header, but I still have the below error while I call an api:</p>
  
  <blockquote>
    <p>No 'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin '<a href="http://localhost:8080" rel="noreferrer">http://localhost:8080</a>' is therefore not allowed
    access. The response had HTTP status code 500. If an opaque response
    serves your needs, set the request's mode to 'no-cors' to fetch the
    resource with CORS disabled.</p>
  </blockquote>
  
  <p>This is my <code>Startup.cs</code> code related to <code>CORS</code>:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
  
      // other lines of code
      services.AddCors(options =&gt;
      {
          options.AddPolicy("AllowAll",
              builder =&gt;
              {
                  builder
                  .AllowAnyOrigin()
                  .AllowAnyMethod()
                  .AllowAnyHeader();
              });
      });
  
      services.Configure&lt;MvcOptions&gt;(options =&gt;
      {
          options.Filters.Add(new CorsAuthorizationFilterFactory("AllowAll"));
      });
      // other lines of code
  }
  
  public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  {
      loggerFactory.AddConsole(Configuration.GetSection("Logging"));
      loggerFactory.AddDebug();
      app.UseCors("AllowAll");
      app.UseAuthentication();
      app.UseMvc();
  }
  </code></pre>
  
  <p>This is my react code:</p>
  
  <pre><code>function save(message) {
      const requestOptions = {
          method: 'POST',
          mode: 'cors',
          headers: { ...authHeader(), 
              'Content-Type': 'application/json',    
              'Access-Control-Allow-Origin':'*',
  
      },
          body: JSON.stringify(message)               
      };
      return fetch(config.apiUrl + '/message/save', requestOptions).then(handleResponse, handleError);
  }
  </code></pre>
  
  <p>Thanks for your responding.</p>