I want to be able to stop processing a request if the JSON that is posted to my controller's action is too large.
The size limit will vary so I don't want to hard code this value in my web.config
Is there a way to check in my controllers action? Say my limit is 100kb, if it goes over I don't want to waste the servers CPU, I just want to halt and return right away.
There is such a setting for this in the Json class (See Code Below):
var jsonResult = Json(jsonString, JsonRequestBehavior.AllowGet);
jsonResult.maxJsonLength = int.MaxValue;
return jsonResult;
It can also be done in configuration like this (Web.config):
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With