I am sending a POST request to an MVC controller with a large amount of JSON data in the body and it is throwing the following:
ArgumentException: Err
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
So, although this is a rather disagreeable solution, I got around the problem by reading the request stream manually, rather than relying on MVC's model binders.
For example, my method
[HttpPost]
public JsonResult MyMethod (string data = "") { //... }
Became
[HttpPost]
public JsonResult MyMethod () {
Stream req = Request.InputStream;
req.Seek(0, System.IO.SeekOrigin.Begin);
string json = new StreamReader(req).ReadToEnd();
MyModel model = JsonConvert.DeserializeObject<MyModel>(json);
// use model...
}
This way I could use JSON.NET and get around the JSON max length restrictions with MVC's default deserializer.
To adapt this solution, I would recommend creating a custom JsonResult factory that will replace the old in Application_Start()
.