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.csUsing 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 UploadUpload prompt Successful2. Upload files larger than 4MSelect upload 4.3M PDF file upload report to Yellow Pages3. 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 errorLook 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 filteringSelect Edit feature limit on the rightIn the popup page, we see that the default request limit is exactly 30MModify 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