Asp. NET file Upload size limit solution

Source: Internet
Author: User
Tags system log server hosting

We all know that ASP. NET provides us with the file Upload server control FileUpload, the largest file that can be uploaded by default is 4M, if you want to change the size limit of the uploaded file, we can add the Maxrequestleng in the httpruntime element in Web. config The Th property is set to size, and in order to support large file upload timeouts You can add the Executiontimeout property to set the time-out. There are many such examples on the Internet, but is the reality like this?

test EnvironmentIIS 7.5,. NET 3.5 SP1 test Page uploadfile.aspx
<%@ page language= "C #" autoeventwireup= "true" codefile= "UploadFile.aspx.cs" inherits= "UploadFile"%>
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:fileupload id= "FileUpload1" runat= "Server"/>
<asp:button id= "Button1" runat= "Server" text= "button"/>
</div>
</form>
</body>
test Page UploadFile.aspx.cs
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
public partial class UploadFile:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (fileupload1.filecontent! = null)
{
Fileupload1.saveas (Server.MapPath ("/files/" +fileupload1.filename));
}
}
}
actual Test 1. Upload files that are less than 4MChoose 2.7M PDF File Upload

Upload prompt Successful

2. Upload files larger than 4M

Select upload 4.3M PDF file upload report to Yellow Pages

3. Modify the Web. config file to set the upload file size limitModify the Web. config to increase the size limit of the file that can be uploaded, increasing the execution time limit

Upload successful4. Upload files that are larger than 30MThe actual situation of this problem is that we use the third-party upload file components, through the JS call third-party ActiveX control upload files, modify the Web. config after uploading more than 30M files, reported the following error

Look at the Windows system log, you can see the following log error, see the exception information, we can guess the request is very long, but we set the maximum request length Ah, and far more than 30M. Just calm down and think about it. It is possible that IIS is restricted, querying the relevant IIS data and discovering that this is the case. Exception message: The maximum request length was exceeded.
In System.Web.HttpRequest.GetEntireRawContent ()
In System.Web.HttpRequest.GetMultipartContent ()
In System.Web.HttpRequest.FillInFormCollection ()
In System.Web.HttpRequest.EnsureForm ()
In System.Web.HttpRequest.get_HasForm ()
In System.Web.UI.Page.GetCollectionBasedOnMethod (Boolean dontreturnnull)
In System.Web.UI.Page.DeterminePostBackMode ()
In System.Web.UI.Page.ProcessRequestMain (Boolean Includestagesbeforeasyncpoint, Boolean Includestagesafterasyncpoint)
5. Modifying the configuration of IISSelect your site, and double-click request filtering

Select Edit feature limit on the right

In the popup page, we see that the default request limit is exactly 30M

Modify the request size limit to the appropriate value, and then restart the site after saving.Summary1. ASP. NET as Microsoft's Web services Framework, which defines the size and execution time limits of Web requests. At the same time it provides the basic framework for uploading files, and provides us with the UploadFile server control, which ultimately also transmits the file data via HTTP to the server side, naturally also by the request size and execution time limit, but the general request can not reach this limit, This threshold is often only touched when the file is uploaded. 2. IIS, as a legal server hosting ASP. NET on the Windows platform, can also uniformly set the size limit that is sent to itself here, according to normal logic. Also, because IIS routes requests for specific types of files to ASP. Requests such as JS, CSS, and pictures are not limited by the size of the request in ASP., which also explains from one side that it is necessary to add control to IIS. 3. The requested length check can only be routed to ASP. After the IIS limit is passed, the subsequent pipeline processing steps can be performed only if the checksum is finally limited by the length of the ASP.

Asp. NET file Upload size limit solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.