We thought the file size limit
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?
<maxrequestlength= " executiontimeout=" "/>
Test environment
IIS 7.5,. NET 3.5 SP1
Test Page uploadfile.aspx
<%@ Page Language="C #"AutoEventWireup="true"CodeFile="UploadFile.aspx.cs"Inherits="UploadFile" %> <!DOCTYPE HTML> <HTMLxmlns= "http://www.w3.org/1999/xhtml"><Headrunat= "Server"><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/> <title></title></Head><Body> <formID= "Form1"runat= "Server"> <Div> <Asp:fileuploadID= "FileUpload1"runat= "Server" /> <Asp:buttonID= "Button1"runat= "Server"Text= "button" /> </Div> </form></Body></HTML>
Test Page UploadFile.aspx.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial classuploadfile:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { if(Fileupload1.filecontent! =NULL) {Fileupload1.saveas (Server.MapPath ("/files/"+fileupload1.filename)); } } }
Actual test
- Upload files that are less than 4M
Choose 2.7M PDF File Upload
Upload prompt Successful
2. Upload files larger than 4M
Choose to upload a 4.3M PDF file
Report to Yellow Pages after uploading
3. Modify the Web. config file to set the upload file size limit
Modify the Web. config to increase the size limit of an uploaded file, increasing the execution time limit
<maxrequestlength= "2048000" executiontimeout= "+"/ >
Re-select the PDF file just 4.3M, re-upload
Upload successful
4. Upload files that are larger than 30M
The real environment of this problem is that we use the third-party upload file component, through JS call third-party ActiveX control upload file, 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. Static
Come 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 the System.Web.UI.Page.DeterminePostBackMode () in System.Web.UI.Page.ProcessRequestMain (Boolean Includestagesbeforeasyncpoint, Boolean Includestagesafterasyncpoint)
5. Modifying the configuration of IIS
Select 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.
Summarize
1. ASP. NET as Microsoft's Web services Framework, which defines the size and execution time limits of Web requests. It provides a basic framework for uploading files and provides us with UploadFile server control
, it is also through the HTTP transfer file data to the server side, naturally also by the request size and execution time limit, but the general request can not reach this limit, often is the upload file time will touch
This valve value.
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 will only target specific types of text
Request is routed 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.