2009-11-05 99 views
1

有一个限制,我不能上传超过这个限制的文件。如何上传2MB以上的文件

当我设置maxRequestLength财产超过这个限制,我会得到这个错误:

The value for the property 'maxRequestLength' is not valid. The error is: The value must be inside the range 0-2097151.

所以,我怎么能上传图片,也就是5 MB大?我无法使用FTP访问。

+0

什么是你的maxRequestLength的值设置为? – 2009-11-05 23:04:41

+0

也许它需要太长时间,会话超时发生? – gerleim 2009-11-05 23:09:10

回答

8

这是在千字节,而不是字节:

maxRequestLength on MSDN:

Indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes. The default is 4096 KB (4 MB).

0

的值是千字节,所以设置了maxRequestLength到8124将允许8MB上传

0

的maxRequestLength的单位为KB 。默认值是4096,这意味着4MB。

它只是修改一个值像32000

0

您可以更改网络的最大请求长度。配置文件

<httpRuntime maxRequestLength="102400" /> 

记住,用户仍将受到带宽的问题是有限的,可能会收到超时错误。

你可以把这样的事情在你的Global.asax文件来处理更友好的方式错误:

protected void Application_Error(object sender, EventArgs e) 
{ 
    Exception sourceException = Server.GetLastError().InnerException != null ? Server.GetLastError().InnerException : Server.GetLastError().GetBaseException(); 

    if (sourceException.Message.Equals("Maximum request length exceeded.") && Request.ContentType.Contains("multipart/form-data")) 
    { 
     HttpContext.Current.Server.ClearError(); 
     string path =//specify page to redirect to 
     HttpContext.Current.Response.Redirect(path);/*in casini just get cannot connect page, but in iis get appropriate page*/ 
    } 

}