Asp.net maximum input length exceeded

I have a .net web server working with Nancyfx. I have a route that should upload an image, this image is sent with the client in json byte64 encoding, as well as with other attributes. When I try to associate incoming json with my model, I got the following exception: "The maximum length of the input JSON signal is exceeded."

Something like that:

Post["/Upload", true] = async(_, ctx) => { UploadModel model = null; model = this.Bind<UploadModel >(); . . . } 

I read that changing the value of "maxJsonLength" in my web.config handles this problem, but when I set it to a higher value, there is no effect:

 <scripting> <webServices> <jsonSerialization maxJsonLength="50000000"/> </webServices> </scripting> 

Along with maxRequestLength:

 <httpRuntime targetFramework="4.5" maxRequestLength="1000000"/> 

For some small images (5KB, 50KB) there is no problem with linking, but when I send photos of 144KB or higher, it causes me an error.

Any thoughts? If I missed any relevant information, just ask me

+6
source share
1 answer

Ignore the guys, I just found the answer:

The nancy documentation says: "If you encounter a Nancy.Json.JsonSettings.MaxJsonLength Exceeded error because your payload is too high, change this limit in your Bootsrapper ..."

So, I did this:

 public class Bootstrapper : DefaultNancyBootstrapper { protected override void ApplicationStartup(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines) { base.ApplicationStartup(container, pipelines); Nancy.Json.JsonSettings.MaxJsonLength = int.MaxValue; } } 

Now, more MaxJsonLength errors, hope this helps someone in the future!

+15
source

Source: https://habr.com/ru/post/971257/


All Articles