title: Blazor Request blocked by CORS policy
body: <p>I am trying to send a request from a <code>Blazor</code>(client-side) client to a server and i keep getting this error: </p>
  
  <blockquote>
    <p>Access to fetch at '[route]' (redirected from '[other route]') from
    origin '[origin route]' has been blocked by CORS policy: No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. 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>On the server i have already added the <code>CORS</code> extension in the pipeline to no avail:</p>
  
  <p><strong>Server Startup</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services) {
              services.AddCors();
              services.AddResponseCompression(options =&gt; {
                  options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
                  {
                      MediaTypeNames.Application.Octet,
                      WasmMediaTypeNames.Application.Wasm,
                  });
              });
  }
   public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
  
              app.UseCors(x =&gt; x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials());
  
              app.UseResponseCompression();
  
              app.UseMvc();
  
              app.UseBlazor&lt;Client.Startup&gt;();
  
          }
  </code></pre>
  
  <p><strong>Blazor Client request</strong></p>
  
  <pre><code>public async Task&lt;Catalog&gt; GetCatalogAsync() {
              try {
                  HttpRequestMessage message = new HttpRequestMessage {
                      RequestUri = new Uri(BASE_PATH + Routes.GET_CATALOG), //BASE_PATH= 172.XX.XX.XX:8600
                      Method = HttpMethod.Get
                  };
                  var resp = await this.client.SendAsync(message); // client is HttpClient
                  var resultString = await resp.Content.ReadAsStringAsync();
                  var result = JsonConvert.DeserializeObject&lt;Catalog&gt;(resultString);
                  return data;
  
              } catch (Exception ex) {
  
                  throw;
              }
  
          }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>[HttpGet]
  [Route(Routes.GET_CATALOG)]
  public async Task&lt;Catalog&gt; GetCatalogAsync() {
      try {
          var registry = await this.adminService.GetCatalogAsync();
          return registry;
      } catch (Exception ex) {
  
          throw;
      }
  }
  </code></pre>
  
  <p><strong>POCO</strong></p>
  
  <pre><code>[Serializeable]
  public struct Catalog{
  }
  </code></pre>
  
  <p>What else can i do to be able to reach my server? Is it due to Blazor ?
  As you can see i have already added the <code>UseCors(...)</code>.</p>
  
  <p><strong>P.S</strong><Br>
  I have published my Blazor Server project together with the Client.They are in the same directory.This folder i placed it on a computer,and i am trying from my computer to open blazor :  <code>172.168.18.22:8600/</code></p>
  
  <p><strong>Update</strong><br>
  I have also tried adding headers to my <code>HttpRequestMessage</code> to no avail:</p>
  
  <pre><code>HttpRequestMessage message = new HttpRequestMessage {
                      RequestUri = new Uri(BASE_PATH + Routes.GET_CATALOG),
                      Method = HttpMethod.Get,
  
                  };
  message.Headers.Add("Access-Control-Allow-Origin","*");
  message.Headers.Add("Access-Control-Allow-Credentials", "true");
  message.Headers.Add("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Content-Type");
  </code></pre>