title: Web.config jsonSerialization maxJsonLength ignored
body: <p>I have an <code>MVC3</code> application running under <code>.NET 4.0</code> and when I use <code>JavascriptSerializer.Deserialize</code> I'm getting an error.</p>
  
  <blockquote>
    <p>Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.</p>
  </blockquote>
  
  <p>Reading <a href="https://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config">Can I set an unlimited length for maxJsonLength in web.config</a> I put the <code>jsonSerialization maxJsonLength</code> key in my web.config but it gets ignored. Though I can set the <code>JavaScriptSerializer.MaxJsonLength</code> property in code and it works fine.</p>
  
  <p>I would like to have the value in the <code>Web.config</code> rather than code. Here is how I am using <code>JavaScriptSerializer</code>.</p>
  
  <pre><code>Dim client As New WebClient
  ...
  Dim result = _client.DownloadString("Test")
  Dim serializer = New JavaScriptSerializer
  Return serializer.Deserialize(Of Foo)(result)
  </code></pre>
  
  <p>Here is my <code>Web.config</code></p>
  
  <pre><code>&lt;configuration&gt;
      &lt;configSections&gt;
      ...
      &lt;/configSections&gt;
      &lt;appSettings&gt;
      ...
      &lt;/appSettings&gt;
      &lt;system.web&gt;
      &lt;customErrors mode="On"&gt;
        &lt;error statusCode="404" redirect="/Http404"/&gt;
        &lt;error statusCode="403" redirect="/Http403"/&gt;
        &lt;error statusCode="550" redirect="/Http550"/&gt;
      &lt;/customErrors&gt;
      &lt;compilation debug="true" targetFramework="4.0"/&gt;
      &lt;pages controlRenderingCompatibilityVersion="4.0"&gt;
        &lt;namespaces&gt;
          &lt;add namespace="System.Web.Helpers"/&gt;
          &lt;add namespace="System.Web.Mvc"/&gt;
          &lt;add namespace="System.Web.Mvc.Ajax"/&gt;
          &lt;add namespace="System.Web.Mvc.Html"/&gt;
          &lt;add namespace="System.Web.Routing"/&gt;
          &lt;add namespace="System.Web.WebPages"/&gt;
        &lt;/namespaces&gt;
      &lt;/pages&gt;
    &lt;/system.web&gt;
    &lt;system.web.extensions&gt;
      &lt;scripting&gt;
        &lt;webServices&gt;
          &lt;jsonSerialization maxJsonLength="50000000"/&gt;
        &lt;/webServices&gt;
      &lt;/scripting&gt;
      &lt;/system.web.extensions&gt;
   &lt;system.webServer&gt;
   ....
  &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>