C # solution for uploading files up to 4 MB by default

Source: Internet
Author: User
Tags metabase

1. Environment: window 2003, IIS6.0
First, you must modify the maximum number of asp requests in IIS6.0. The default value is 200 K;
Method: Open metabase. XML in C: \ Windows \ System32 \ Inetsrv,
Modify AspMaxRequestEntityAllowed for the value you need (such as "1073741824", 1 GB );
Technical Background:
In IIS 6.0, the AspMaxRequestEntityAllowed attribute specifies the maximum number of bytes that an ASP Request can use. if the request Length contained in the Content-Length header exceeds the value of AspMaxRequestEntityAllowed, IIS returns a 403 error message.
This attribute value is similar to MaxRequestEntityAllowed, but is for ASP requests. if you know that your ASP application only needs to process a small amount of request data, you can set the global MaxRequestEntityAllowed attribute at the World Wide Web Hing Service (WWW Publishing Service) level to 1 MB, set AspMaxRequestEntityAllowed to a smaller value.
Note: Stop the IIS service before editing the file. Otherwise, the modified file cannot be saved.
It can also be solved as follows:
IIS6 Resource Kit Tools (http://www.microsoft.com/downloads/details.aspx? FamilyID = metric & displaylang = en). After installation, you modified the attribute (local) \ LM \ W3SVC \ AspMaxRequestEntityAllowed (200 K = 204800 by default) using Metabase Explorer and changed it to 1 GB; at the same time, the AspScriptTimeout attribute is modified to adjust the time limit so that you can upload large files.
2, in. net
(1) Add an httpRuntime primary key to the web. comfig file.
<HttpRuntime executionTimeout = "90" maxRequestLength = "40960" useFullyQualifiedRedirectUrl = "false"
MinFreeThreads = "8" minLocalRequestFreeThreads = "4" appRequestQueueLimit = "100"/>
MaxRequestLength = "40960" indicates the maximum number of requests. The unit is K.
(2) modify the C: \ WINDOWS \ Microsoft. NET \ Framework \ v1.1.4322 \ CONFIG \ machine. config file
<HttpRuntime executionTimeout = "190" maxRequestLength = "40960"
MaxRequestLength = "40960" indicates the maximum number of requests. The unit is K.
After the experiment, (1) and (2) only one can be used.

Configuring httpRuntime also allows FileUpload to upload larger files. However, if it is too largeDenial-of-service attacks caused by a large number of files being transferred to the server(Attributes are described)

<HttpRuntime>

="true|false" maxRequestLength="size in kbytes" executionTimeout="seconds" minFreeThreads="number of threads" minFreeLocalRequestFreeThreads="number of threads" appRequestQueueLimit="number of requests" versionHeader="version string"/>
Attribute
Attribute Option Description
AppRequestQueueLimit The maximum number of requests that ASP. NET queues for applications. Requests are queued when there are not enough free threads to process requests. When the queue exceeds the limit specified in this setting, the incoming request is rejected through the "503-the server is too busy" error message.
ExecutionTimeout Indicates the maximum number of seconds allowed to execute a request before it is automatically disabled by ASP. NET.
Enable Specifies whether to enable application domains at the current node and subnode level. The default value isTrue.
True Specifies to enable the application domain.
False Specifies to disable the application domain. The application will not load in the memory, and any client request will cause an error code 404.
IdleTimeOut Specifies how long the application domain will be closed after idle time. The default value is20 minutes.
EnableKernelModeCache Specifies whether to enable the output cache. Currently, this attribute only takes effect after IIS version 6.0 or later is installed. The output cache configuration and request type determine whether to cache the content.

To Cache the response, the following conditions must be met:

  • You must enable the cache explicitly by using page commands or using the cache API.
  • The cache must have an expiration policy so that the kernel knows when to discard the cache.
  • The cache cannot contain any variable headers or parameters.
  • The request cannot require any authentication.
True Specify to enable cache.
False Disable cache.
MaxRequestLength Indicates the maximum file upload size supported by ASP. NET. This restriction can be used to prevent DoS attacks caused by a large number of files being transferred to the server. The specified size is in KB. The default value is 4096 KB (4 MB ).
MinFreeLocalRequestFreeThreads ASP. NET maintains the minimum number of free threads allowed to execute new local requests. The number of threads is reserved for requests passed in from the local host to prevent some requests from sending subrequests to the local host during processing. This avoids possible deadlocks caused by recursive re-entering the Web server.
MinFreeThreads The minimum number of free threads allowed to execute new requests. ASP. NET requires additional threads to complete their processing requests so that these threads remain free.
UseFullyQualifiedRedirectUrl Indicates whether client redirection is fully qualified (in the format of {HYPERLINK "http: // server/path"}, which is required by some mobile controls ), or indicates whether to send relative redirection to the client.
True Specify that the client redirection needs to be sent in a fully qualified format. This is achieved by automatically converting all redirects in not fully qualified formats to fully qualified formats.
False The specified client redirection does not need to be automatically converted to a fully qualified format.FalseIs the default option.
VersionHeader Specifies the value of the version header that ASP. NET sends with each response. Microsoft Visual Studio. NET uses this attribute to determine the current ASP. NET version. This is not necessary for the product environment, and you can remove this attribute from Web. config or Machine. config, or set this attribute to a null string (VersionHeader= "") To disable it.

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.