title: Problem with cors and jquery while uploading a file
body: <p>I'm trying to send a file to an API on a system I'm developing. The front end is using jquery while back-end is using C# (.Net Core).</p>
  <p>I have enabled CORS in the backend, and it is all working well. Upload works fine while in localhost, but when I try it on the actual servers, I get this CORS error.</p>
  <p>How I send the data:</p>
  <pre><code>            $('#input-upload').change(function(event) {
                  self.form = new FormData();
                  self.form.append('arquivo', event.target.files[0]); 
  
                  $.ajax(
                  {
                      url: ControleDePagamentosModel.getUploadUrl(self.selected), 
                      data: self.form,
                      processData: false,
                      contentType: false,
                      type: 'POST'
                  })
                  .done(function(data)
                  {
                      console.log(data);
                      if (data.error)
                      {
                          alert(data.message);
                      }
                      else if (data.message)
                      {
                          alert(data.message);
                      }
                  })
                  .fail(function()
                  {
                      alert(&quot;Erro de comunicação com o servidor de dados!&quot;);
                  });  
              });
  </code></pre>
  <p>The server endpoint:</p>
  <pre><code>[HttpPost]
  [Route(&quot;upload/{id}/{username}&quot;)]
  public async Task&lt;ResponseDTO&gt; UploadFGTSAsync([FromForm] IFormFile arquivo, int id, string username)
  {
      string path = &quot;&quot;;
  
      if (arquivo !=null &amp;&amp; arquivo.Length &gt; 0)
      {
          ...
  
  </code></pre>
  <p>EDIT: My CORS configuration:</p>
  <pre><code>        public void ConfigureServices(IServiceCollection services)
          {
              services.AddRouting();
              services.AddCors(o =&gt; o.AddPolicy(&quot;apiPolicy&quot;, builder =&gt;
              {
                  builder.AllowAnyOrigin()
                         .AllowAnyMethod()
                         .AllowAnyHeader();
              }));
              services.AddMvc().AddNewtonsoftJson(
                  options =&gt; 
                  {
                      options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                      //options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                      options.SerializerSettings.MaxDepth = 1;
                  }
              );
              services.AddControllers();
              services.AddSwaggerGen(c =&gt;
              {
                  c.SwaggerDoc(&quot;v1&quot;, new OpenApiInfo { Title = &quot;EmccampAPI&quot;, Version = &quot;v1&quot; });
              });
  
              services.Configure&lt;IISOptions&gt;(o =&gt;
              {
                  o.ForwardClientCertificate = false;
              });
  
              services.AddHttpClient();
              services.AddDbContext&lt;DBCONTROLEMPContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString(&quot;ControlEmp&quot;)));
              //services.AddDbContext&lt;RMContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString(&quot;RM&quot;)));
  
              services.AddTransient&lt;IConfigService, ConfigService&gt;();
  }
  </code></pre>
  <p>Note that all other requests work.</p>