1、如何解决“HttpException (0x80004005): 超过了最大请求长度”问题
堆栈信息
“/”应用程序中的服务器错误。
超过了最大请求长度。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Web.HttpException: 超过了最大请求长度。
[HttpException (0x80004005): 超过了最大请求长度。]
System.Web.HttpRequest.GetEntireRawContent() +9936248
System.Web.HttpRequest.GetMultipartContent() +63
System.Web.HttpRequest.FillInFormCollection() +160
System.Web.HttpRequest.EnsureForm() +69
System.Web.HttpRequest.get_Form() +13
System.Web.HttpRequest.get_Item(String key) +42
DevExpress.Web.ASPxHttpHandlerModule.IsCallBack(HttpRequest request) +81
DevExpress.Web.ASPxHttpHandlerModule.PreSendRequestHeadersHandler(Object sender, EventArgs args) +110
解决方法:修改web.config文件
注意在mvc中有两个web.config文件,如下图,一个位于Views下,是用来控制view中的文件;还有一个在位于根目录下,对所有文件起作用。我们先修改根目录下web.config
1)在<system.web>下添加最大请求长度设置为1G
<system.web>
<!--最大请求长度,单位为KB(千字节),默认为4M,设置为1G,上限为2G -->
<httpRuntime targetFramework="4.6.1" maxRequestLength="1048576" executionTimeout="3600" />
</system.web>
2)在<system.webServer>下添加允许上传文件长度设置为1G
<system.webServer>
<!--允许上传文件长度,单位字节(B),默认为30M,设置为1G,最大为2G -->
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824"/>
</requestFiltering>
</security>
</system.webServer>
2、使用JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了为 maxJsonLength属性
解决办法:
1)在Views下的web.config增加如下节点到下
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="1024000000" />
</webServices>
</scripting>
</system.web.extensions>
2)
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
jsSerializer.MaxJsonLength = Int32.MaxValue;
参考网址:
https://www.jb51.net/article/88698.htm
https://www.cnblogs.com/wangfuyou/p/6046307.html