title: ajax post to mvc receiving 302 (redirect) in production environment
body: <p>I'm investigating a problem for around 2 weeks and I can't find a solution. </p>
  
  <p>I have one ajax calling that is receiving redirect (302) just in production environment and just for this calling. </p>
  
  <p>I've searched for all possibilities that I've found and until now I couldn't find why the redirect is happening.</p>
  
  <p>I've checked authorization, version of the code, IIS configurations and so on, but nothing at all solved the problem.</p>
  
  <p>The request as you can see bellow, is an upload of a simple .csv file. I have another similar request (actually it is identical) that is working fine both on homologation and production environment. Just this calling isn't working and only for the production environment.</p>
  
  <p>Ajax post:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function SubmitButtonOnclick() {
      var formData = new FormData();
      var file = document.getElementById("selecionaEmail").files[0];
      formData.append("selecionaEmail", file);
  
      $.ajax({
          url: '@Url.Action("ModalEmailsUpload", "Mail")',
          type: 'POST',
          dataType: 'json',
          data: formData,
          contentType: false,
          processData: false,
          success: function (data) {
  
              var count = 0;
              $.each(data, function (i, item) {
                  count++;
              });
  
              if (count &gt; 0) {
                  $("#mensagem").css("color", "#3f8324");
                  $("#mensagem").text("File uploaded. Choose one option:");
   
                  if ($("#pfIncluir").is(":disabled")) {
                      $("#pfIncluir").removeAttr('disabled');
                  }
  
                  if ($("#pfExcluir").is(":disabled")) {
                      $("#pfExcluir").removeAttr('disabled');
                  }
              }
  
          },
          error: function (error) {
              $("#mensagem").css("color", "#ff0000");
              $("#mensagem").text(error.responseText);
              $("#pfIncluir").attr("disabled", true);
              $("#pfExcluir").attr("disabled", true);
  
          }
      });</code></pre>
  </div>
  </div>
  </p>
  
  <p>The action signature:</p>
  
  <pre>
  
      [HttpPost]
      public ActionResult ModalEmailsUpload()
      {
          //it's just returning a string as result of the validation
      }
  
  </pre>
  
  <p>Here the logs I took from browser:</p>
  
  <p>Homologation:</p>
  
  <pre>
  POST /Mail/ModalEmailsUpload HTTP/1.1
  Host: ***
  User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:55.0) Gecko/20100101 Firefox/55.0
  Accept: application/json, text/javascript, */*; q=0.01
  Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
  Accept-Encoding: gzip, deflate, br
  X-Requested-With: XMLHttpRequest
  Referer: ***
  Content-Length: 362
  Content-Type: multipart/form-data; boundary=---------------------------322973251128192
  Cookie: ASP.NET_SessionId=jo2j042lp2xsnzsjsslddmf0; .Login=07E0F5F86E9EF39DC84A926E79C414B2E5802286712F9FB439106E31200CF139CF78E0EA8B6A680DD3CE80DE388EBEAC8176392FFDCFCFEFDC905BBA4AA0D66671E5A980C5CABDF677B88FB1C37F13F458B92ED3F1906AFDB7616AA010C34B0559F426D8F6807E8548B5E9E95A4F1891F0B28DA9D2CF03FC3D850C3961AE1C03FDD3FE2ABCC3F3221D2E8D361C7D3C93783E5A68F3FE9B764A56FB9E0DF1A780; __RequestVerificationToken=GsjCurVxu6w5ZJWY6fn5bk-8QYwkOo-NU8kP_48_eVnSjNE_VgpS9QTKIz4rd4W43H5DM1zLD5Ei-Chmgua4G77ylNSX2yOdGHEwV6bZ_UA1
  Connection: keep-alive
  -----------------------------322973251128192
  Content-Disposition: form-data; name="selecionaEmail"; filename="_csv_virgula - parcial.csv"
  Content-Type: application/vnd.ms-excel
  
  CP,LOJA,EMAIL
  10001,111,test1@teste.com.br
  -----------------------------322973251128192--
  
  HTTP/1.1 200 OK
  Cache-Control: private
  Content-Type: application/json; charset=utf-8
  Server: Microsoft-IIS/7.5
  X-AspNetMvc-Version: 5.2
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  ----------------------------------------------------------
  </pre>
  
  <p>Production:</p>
  
  <pre>
  POST /Mail/ModalEmailsUpload HTTP/1.1
  Host: ***
  User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:55.0) Gecko/20100101 Firefox/55.0
  Accept: application/json, text/javascript, */*; q=0.01
  Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
  Accept-Encoding: gzip, deflate, br
  X-Requested-With: XMLHttpRequest
  Referer: ***
  Content-Length: 358
  Content-Type: multipart/form-data; boundary=---------------------------4390192952067
  Cookie: .Login=40DDB91B4FCD780BD93E2B32BE6D603444BAA74AD3DE6440E55372C23B48A25BE74C15F91A3161800B5B049AB2E6045EB660E016D167CB1A3D7DE5F10C71ED83105365E42E99BDAEC620559C6FC5C36D0840C8B4ECA5DBE76ED20DF212AE5A4EC2D9B105F3FE5DEEDF3406D35A24FAD7FC6927236CC29DE55ACC3C55EBCD6DEFF6F5F597164DD3625105E9708C421B0240AF2CCC53BD9293E86276A151F6E432; ASP.NET_SessionId=y25h2jwy4pukqqo0nl0oz30n; __RequestVerificationToken=g1o3D2naXZUJS4dakmMdzn9T1OQ4lScnjrYdKOhM-s3H5ZhkSpq9JnOMv51N-GQJ-gn2yspgPSQC39H9OPVPcBXOCaHW0V2bVrj8UHUBZ9A1
  Connection: keep-alive
  -----------------------------4390192952067
  Content-Disposition: form-data; name="selecionaEmail"; filename="_csv_virgula - parcial.csv"
  Content-Type: application/vnd.ms-excel
  
  CP,LOJA,EMAIL
  10001,111,test1@teste.com.br
  -----------------------------4390192952067--
  
  HTTP/1.1 302 Found
  Cache-Control: private
  Content-Type: text/html; charset=utf-8
  Location: /Erro?aspxerrorpath=/Mail/ModalEmailsUpload
  Server: Microsoft-IIS/7.5
  X-AspNetMvc-Version: 5.2
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  ----------------------------------------------------------
  
  GET /Erro?aspxerrorpath=/Mail/ModalEmailsUpload HTTP/1.1
  Host: ***
  User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:55.0) Gecko/20100101 Firefox/55.0
  Accept: application/json, text/javascript, */*; q=0.01
  Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
  Accept-Encoding: gzip, deflate, br
  Referer: ***
  X-Requested-With: XMLHttpRequest
  Cookie: .Login=40DDB91B4FCD780BD93E2B32BE6D603444BAA74AD3DE6440E55372C23B48A25BE74C15F91A3161800B5B049AB2E6045EB660E016D167CB1A3D7DE5F10C71ED83105365E42E99BDAEC620559C6FC5C36D0840C8B4ECA5DBE76ED20DF212AE5A4EC2D9B105F3FE5DEEDF3406D35A24FAD7FC6927236CC29DE55ACC3C55EBCD6DEFF6F5F597164DD3625105E9708C421B0240AF2CCC53BD9293E86276A151F6E432; ASP.NET_SessionId=y25h2jwy4pukqqo0nl0oz30n; __RequestVerificationToken=g1o3D2naXZUJS4dakmMdzn9T1OQ4lScnjrYdKOhM-s3H5ZhkSpq9JnOMv51N-GQJ-gn2yspgPSQC39H9OPVPcBXOCaHW0V2bVrj8UHUBZ9A1
  Connection: keep-alive
  
  HTTP/1.1 500 Internal Server Error
  Cache-Control: private
  Content-Type: application/json; charset=utf-8
  Server: Microsoft-IIS/7.5
  X-AspNetMvc-Version: 5.2
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  ----------------------------------------------------------
  </pre>