我在.net网站上与Nancyfx合作。我有一个必须上传图像的路由,这个图像是从json byte64编码的客户端发送的,以及其他属性。当我尝试将传入的json与我的模型绑定时,我得到了下一个异常:“已超出最大JSON输入长度。”
这样的事情:
Post["/Upload", true] = async(_, ctx) =>
{
UploadModel model = null;
model = this.Bind<UploadModel >();
.
.
.
}
我已经读过在我的web.config中更改“maxJsonLength”的值会处理这个问题,但是当我为它设置一个更高的值时,没有任何效果:
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
与maxRequestLength一起:
<httpRuntime targetFramework="4.5" maxRequestLength="1000000"/>
对于一些较小的图片(5KB,50KB),绑定没有问题,但是当我发送大小为144KB及以上的图片时,它会给我带来错误。
有什么想法?如果我错过了一些相关信息,请问我
答案 0 :(得分:16)
别介意,我刚刚找到答案:
在nancy文档中,它说“如果您遇到Nancy.Json.JsonSettings.MaxJsonLength Exceeded错误,因为您的有效负载太高,请在Bootsrapper中更改该限制...”
所以我做到了:
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;
}
}
现在,不再有MaxJsonLength错误,希望将来对某人有所帮助!