开发者

How to upload a file over 2MB

There is a limit, i cant upload a file over this limit.

When i set the maxRequestLength property over this limit i will get this error:

The value for the property 'maxRequestLength' is not valid. The error is: The value must be inside the range 0-2097开发者_运维技巧151.

So how could i upload an image that is 5 MB big ? I can't use FTP access.


It's in kilobytes, not bytes:

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).


The value is in kilobytes, so setting maxRequestLength to 8124 would allow 8MB uploads


The unit of maxRequestLength is KB. The default value is 4096 which means 4MB.

Just modify it to a value like 32000


You can change the max request length in the web. config file

<httpRuntime maxRequestLength="102400" />

Bear in mind that users will still be limited by bandwidth issues and may receive timeout errors.

You can put something like this in your Global.asax file to handle the errors in a more friendly manner:

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*/ 
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜