Resolving the ASP. NET upload file size limit

Source: Internet
Author: User

The first method, mainly for the IIS6.0 version

First, modify the HttpRuntime node in the configuration Web. config file
For ASP., the default is to allow only 4M files to be uploaded, and the maximum file size can typically be customized by adding the following configuration.
First, modify the HttpRuntime node in the configuration Web. config file
For ASP., the default is to allow only 4M files to be uploaded, and the maximum file size can typically be customized by adding the following configuration.

executiontimeout= "800"

Maxrequestlength= "40960"

Usefullyqualifiedredirecturl= "false"/>


Executiontimeout preset (that is, default) is 90 seconds

Can be modified: executiontimeout = "180"

Maximum upload file size supported by ASP

Configure in Web. config:

Configure the ASP. NET HTTP runtime settings. This section can be declared at the machine, site, application, and subdirectory levels.

<configuration>
<system.web>

Maxrequestlength= "Size in Kbytes"
executiontimeout= "Seconds"
minfreethreads= "Number of threads"
minfreelocalrequestfreethreads= "Number of threads"
apprequestqueuelimit= "Number of requests"
Versionheader= "version string"/>
Optional properties
Property Options Description

useFullyQualifiedRedirectUrl: Indicates whether client redirection is fully qualified (in {HYPERLINK "Http://server/path"} format, which is required for some mobile controls). or indicates whether a relative redirect is sent to the client instead.
TRUE specifies that client redirection needs to be sent in a fully qualified format. This is accomplished by automatically converting all redirects to a fully qualified format that are not fully qualified.
FALSE specifies that client redirection does not need to be automatically converted to fully qualified format. False is the default option.

maxRequestLength: Indicates the maximum file upload size supported by ASP. This restriction can be used to prevent denial of service attacks that result from the user passing a large number of files to the server. The specified size is in kilobytes. The default value is 4096 KB (4 MB).

Executiontimeout: Indicates the maximum number of seconds that a request is allowed to execute before it is automatically closed by ASP.

minFreeThreads: The minimum number of free threads allowed to execute a new request. ASP. NET is a free State for requests that require additional threads to complete their processing.

MinFreeLocalRequestFreeThreads:ASP.NET keeps the minimum number of free threads that are allowed to execute new local requests. The number of threads is reserved for incoming requests from the local host, in case some requests make child requests to the local host during their processing. This avoids possible deadlocks caused by recursive re-entry into the WEB server.

AppRequestQueueLimit:ASP.NET the maximum number of requests that will be queued for the application. When there are not enough free threads to process the request, the request is queued. When the queue exceeds the limit specified in this setting, the incoming request is rejected through the "503-Server Too busy" error message.

Versionheader: Specifies the value of the version header that ASP. NET sends with each response. Microsoft Visual Studio. NET uses this property to determine which version of ASP is currently in use. This is not required for the production environment and can be disabled by removing the property from Web. config or machine.config, or by setting the property to an empty string (versionheader= "").

Example
The following example specifies HTTP run-time parameters for an ASP.

<configuration>
<system.web>
Usefullyqualifiedredirecturl= "true"
Executiontimeout= "45"
versionheader= "1.1.4128"/>
</system.web>
</configuration>

Second, if not yet, you can use the solution provided by homesickness:

We have had this or that problem when uploading large files. Setting a large maxRequestLength value does not completely solve the problem, because ASP. NET blocks until the entire file is loaded into memory before it is processed. In fact, if the file is very large, we often see Internet Explorer showing "the page cannot be displayed-cannot find server or DNS error", as if there is no catch to this error 。 Why? Because this is a client side error, the server side side of the Application_Error is not processed, you can refer to this post to study the mechanism of this error.

Handling server error when upload file too large

The solution is to use the implied httpworkerrequest, using its getpreloadedentitybody and Readentitybody methods to read data from the pipe block built by IIS for ASP.

IServiceProvider Provider = (IServiceProvider) httpcontext.current;
HttpWorkerRequest wr = (HttpWorkerRequest) provider. GetService (typeof (HttpWorkerRequest));
Byte[] bs = WR. Getpreloadedentitybody ();
....
if (!WR. Isentireentitybodyispreloaded ())
{
int n = 1024;
byte[] BS2 = new Byte[n];
while (WR. Readentitybody (bs2,n) >0)
{
.....
}
}

Iii. modification of upload size in IIS

1, first to the process of the IIS service off, that is, the Inetinfo.exe process closed, otherwise the file does not give you change yo ~ ~ ~
2, found in the system directory: Windows/system32/inesrv/metabase.xml "file, find a text editor to open him, I use editpuls (this guy is good, with font color), ctrl+f Find aspmaxrequestentityallowed= "204800" This item, this is the default size of the IIS upload file, the default is 204800Byte, that is 200KB, change it to the size you need!

The second way, mainly for the iis7.0 version

1. Modify the Web config file in the user's own ASP. NET application, add or modify the following red background content

<system.webServer>
<security>
<requestFiltering>
<requestlimits maxallowedcontentlength= "262144000" ></requestLimits>
</requestFiltering>
</security>

2. Open C:/windows/system32/inetsrv/config/schema/iis_schema.xml and find the following:

Program code <element name= "RequestLimits" >
<attribute name= "maxAllowedContentLength" type= "uint" defaultvalue= "30000000"/>
<attribute name= "MaxUrl" type= "uint" defaultvalue= "4096"/>
<attribute name= "maxquerystring" type= "UINT" defaultvalue= "2048"/>
<element name= "Headerlimits" >
<collection addelement= "Add" clearelement= "clear" removeelement= "Remove" >
<attribute name= "Header" Type= "string" required= "true" isuniquekey= "true" validationtype= "nonemptystring"/>
<attribute name= "SizeLimit" type= "UINT" required= "true"/>
</collection>
</element>
</element>


Modify the red part to fit [1] in bytes.

Description

[1]. Iis_schema.xml default is not modifiable, even if the system administrator can not modify, must modify the permissions, and then remove its read-only properties can be modified.

To iis_schema.xml default permissions, click the "Edit" button directly you will find that the permissions are not modified, you have to do the following:
1). Click on the "Advanced" button to enter the Advanced Security settings interface;
2). Switch to the "Owner" tab, click the "Edit" button and select Administrators to confirm;

You can now click the "Edit" button on the "Security" tab to add modify and Write permissions to administrators, and then remove the Iis_schema.xml read-only attribute, the system administrator can modify the file.

The above two ways are my blog on the internet collected, is a more effective method. Before this file upload size limit problem, also tangled for a long time, now finally solved, all kinds of happy. Now put these posted in the blog, hope to give everyone a help, but also leave traces of me, haha!

Ext.: http://blog.sina.com.cn/s/blog_7ae9d7b901014fgi.html

Related Article

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.