title: Send large string to controller using ajax post
body: <p>I'm working on a ASP.NET MVC application, in which I need to send data stored in sessionStorage to a Controller. This storage has a key-value pair, in which the key is 'confirmed'. The value is an array with numbers, like [1,2,3,4,5].</p>
  
  <p>I need to send this array to my controller, and everything works fine, except when this array is too long. I've tried changing the config with:</p>
  
  <pre><code> &lt;appSettings&gt;
      &lt;add key="aspnet:MaxJsonDeserializerMembers" value="1000000" /&gt;
   &lt;/appSettings&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>&lt;system.web.extensions&gt;
      &lt;scripting&gt;  
           &lt;webServices&gt;                                                   
               &lt;jsonSerialization maxJsonLength="1000000" /&gt;                 
           &lt;/webServices&gt;
      &lt;/scripting&gt;
  &lt;/system.web.extensions&gt;
  </code></pre>
  
  <p>but nothing seems to work. It only works fine when the array is not so long.
  Here's my code:</p>
  
  <p><strong>Script:</strong> </p>
  
  <pre><code>$(".enviar").click(function () {
          getSelectedItems();
  
          var seleccion = sessionStorage.confirmed;
  
          $.ajax({
              url: "/Controller/Action",
              type: "POST",
              //data: { confirm: JSON.stringify(seleccion) },
              data: JSON.stringify({ confirm: seleccion }),
              dataType: "json",
              contentType: "application/json; charset=utf-8",
              success: function (returndata) {
                  window.location = "@Url.Action("SomeAction","Controller")";
              },
              error: function (returndata) {
                  window.location.href = "@Url.Action("AnotherAction","Controller")";
              }
          });
  
          //sessionStorage.clear();
      });
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>[HttpPost]
      public ActionResult Action(string confirm)
      {
          if (!String.IsNullOrEmpty(confirm))
          {
              confirm = confirm.Substring(1, confirm.Length - 2);
              var confirmadas = confirm.Split(',');
  
              foreach (var id in confirmadas)
              {
                  //change things in DB
              }
  
              return Json(new { ok = true, newurl = Url.Action("SomeAction", "Controller") });
  
          }
          return Json(new { ok = false, newurl = Url.Action("SomeAction", "Controller") });
      }
  </code></pre>
  
  <p>Please help, I've tried nearly everything and it works sometimes, but other times it doesn't.</p>
  
  <p>Thank you.</p>