title: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at (URL)
body: <p>i have web application with multi layer (Business Layer,Data Access Layer ,Service Layer and Ui Layer) <br>
  i call service layer (web api) in Ui Layer Razor pages(Using JQuery And Ajax )<br>
  as</p>
  
  <pre><code>&lt;button id="btn"&gt;ddd&lt;/button&gt;
  
  script type="text/javascript"&gt;
      $(document).ready(function () {
          var filmtable = $("#DataTableHtmlId");
          $('#btn').click(function() {
              $.ajax({
                  type: 'GET',
                  dataType: "json",
                  contentType: 'application/json; charset=utf-8',
                  url: 'https://localhost:11111/api/film/1',
                  withCredentials: true,
                  AccessControlAllowCredentials: true,
  
                  success: function(data) {
                      alert(data);
                  },
                  error: function(data) {
  
                      alert("err");
                  }
          });
          });
  
      } );
  &lt;/script&gt;
  </code></pre>
  
  <p>when call controller that fire the view that have last ajax calling<br>
  Error This Appear
  <a href="https://i.stack.imgur.com/taD1K.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/taD1K.jpg" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <a href="https://localhost:11111/api/film/1" rel="nofollow noreferrer">https://localhost:11111/api/film/1</a>. (Reason:
    CORS header ‘Access-Control-Allow-Origin’ missing).[Learn More]</p>
    
    <p>Cross-Origin Request Blocked: The Same Origin Policy disallows reading
    the remote resource at <a href="https://localhost:11111/api/film/1" rel="nofollow noreferrer">https://localhost:11111/api/film/1</a>. (Reason:
    CORS request did not succeed).</p>
  </blockquote>
  
  <p>After Search i found many solution 
  as Registering  <strong>Cors</strong> In <strong>ConfigureServices</strong> as</p>
  
  <pre><code>            //Cors policy is added to controllers via [EnableCors("CorsPolicy")]
              //or .UseCors("CorsPolicy") globally
              services.AddCors(options =&gt;
              {
                  options.AddPolicy("CorsPolicy",
                      builder =&gt; builder
                          .AllowAnyOrigin()
                          .AllowAnyMethod()
                          .AllowAnyHeader()
                          .AllowCredentials());
              });
  </code></pre>
  
  <p>and Apply CORS In <strong>Configure</strong> as </p>
  
  <pre><code>        //Apply CORS.
           app.UseCors("CorsPolicy");
           app.UseHttpsRedirection();
           app.UseAuthentication();
           app.UseMvc(); 
  </code></pre>
  
  <p>But error Also Appear Any help?</p>