2009-11-05 46 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*/ 
    } 

}