当我试图在我的网站上上传视频时,我得到错误的最大请求长度超过了。
我怎么解决这个问题?
当我试图在我的网站上上传视频时,我得到错误的最大请求长度超过了。
我怎么解决这个问题?
当前回答
我被我们的网绊倒了。配置文件有多个系统。web部分:当我添加< httpRuntime maxRequestLength="1048576" />到系统时,它工作了。Web部分的配置级别。
其他回答
如果您使用IIS托管应用程序,则默认上载文件大小为4MB。要增加它,请在您的网页中使用下面的部分。配置-
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
对于IIS7及以上版本,您还需要添加下面的行:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
注意:
maxRequestLength以千字节为单位 maxAllowedContentLength以字节为单位
这就是为什么这个配置示例中的值不同。(两者都相当于1gb。)
如果有人正在寻找一种方法来处理这个异常,并向用户显示一个有意义的解释(比如“你正在上传一个太大的文件”):
//Global.asax
private void Application_Error(object sender, EventArgs e)
{
var ex = Server.GetLastError();
var httpException = ex as HttpException ?? ex.InnerException as HttpException;
if(httpException == null) return;
if (((System.Web.HttpException)httpException.InnerException).WebEventCode == System.Web.Management.WebEventCodes.RuntimeErrorPostTooLarge)
{
//handle the error
Response.Write("Too big a file, dude"); //for example
}
}
(ASP。需要net4或以上版本)
如果你有一个请求到站点中的应用程序,确保你在根web.config中设置了maxRequestLength。应用程序web中的maxRequestLength。Config似乎被忽略了。
我正在处理同样的错误,花时间解决后,添加以下行在web。配置文件
<system.web>
<httpRuntime targetFramework="4.7.1" maxRequestLength="1048576"/>
</system.web>
and
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
把所有的答案总结在一个地方:
<system.web>
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
规则:
maxRequestLength(以kb表示)值必须匹配 maxAllowedContentLength(以字节表示)。 大多数时候是你的系统。web section可能已经包含了一个“httpRuntime”。将你的targetFramework设置为你使用的。net版本。
注:
maxRequestLength的默认值是4096 (4mb)。最大值为2147,483,647 maxAllowedContentLength的默认值是30,000,000(大约30mb)。最大值为4,294,967,295
更多信息MSDN