Reference: http://blog.csdn.net/cikeha/article/details/6320.66modify webcong file:
<System. web>
<HttpRuntime maxRequestLength = "40960" // 40 MB, 1 kb = 1024
UseFullyQualifiedRedirectUrl = "true"
ExecutionTimeout = "6000"
UseFullyQualifiedRedirectUrl = "false"
MinFreeThreads = "8"
MinLocalRequestFreeThreads = "4"
AppRequestQueueLimit = "100"
EnableVersionHeader = "true"
/>
</System. web>
Which is closely related to upload:
If the server memory is 512 MB, files with a size of MB can be uploaded.
WebConfig configuration connection timeout
<! --
ExecutionTimeout = "90" to executionTimeout = "720" by wp 2007.9.4 executionTimeout indicates the maximum time limit allowed for request execution, in seconds
MaxRequestLength: indicates the maximum file upload size supported by ASP. NET. The specified size is in KB. The default value is 4096 KB (4 MB ).
-->
<HttpRuntime executionTimeout = "720" maxRequestLength = "65536" latency = "false" minFreeThreads = "8" minLocalRequestFreeThreads = "4" latency = "100" enableVersionHeader = "true"/>
<! --
HttpRuntime is used to configure the asp.net http runtime settings to determine how to process requests to the asp.net application.
ExecutionTimeout: maximum time limit allowed for request execution, in seconds
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 ).
UseFullyQualifiedRedirectUrl: indicates whether the client redirection is fully qualified (in the "http: // server/path" format, which is required by some mobile controls ), or indicates whether to send relative redirection to the client. If it is True, all non-fully-qualified redirects are automatically converted to a fully-qualified format. False is the default option.
MinFreeThreads: specifies the minimum number of free threads allowed to execute new requests. ASP. NET allows a specified number of threads to remain free by appending threads to complete the requests it processes. The default value is 8.
MinLocalRequestFreeThreads: the minimum number of free threads allowed to execute new local requests maintained by ASP. NET. 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.
AppRequestQueueLimit: indicates the maximum number of requests that ASP. NET will queue for the application. 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.
EnableVersionHeader: Specifies whether ASP. NET should output the version header. Microsoft Visual Studio 2005 uses this attribute to determine the current ASP. NET version. This attribute is not required for the production environment and can be disabled.
The web. config settings are now complete.
However, once the size of the uploaded file exceeds the configured file size range, the following error occurs:
This page cannot be displayed
The page you want to view is currently unavailable. The website may encounter technical problems, or you need to adjust the browser settings.
If this problem cannot be solved, capture the error! What should we do?
I have eaten a few fish recently and thought about it. Because this error is caused by a file control foreground error, it is not feasible to use try... catch in the background.
So I thought of using the. NET error capture page mechanism for processing. Feasible.
1. Set web. config first
<CustomErrors mode = "On"/>
2. Create an error. aspx file to capture errors.
3. Add the page command on the front-end page of The aspx page of the uploaded file. ErrorPage = "UploadError. aspx"
4. Add some code in error. aspx to determine whether the error message is a file-caused foreground error.
Public class UploadError: System. Web. UI. Page
{
Private void Page_Load (object sender, System. EventArgs e)
{
Exception ex = Server. GetLastError ();
If (ex! = Null)
{
Response. Redirect (".../error. aspx ");
}
Else // foreground error ex is null
{
Response. Redirect ("uploadexcel. aspx? Err = 1 "); // redirect to the upload page again, and add the err parameter to display the error message.
}
}
5. An error message is displayed.
Public class uploadexcel: System. Web. UI. Page
{
Private void Page_Load (object sender, System. EventArgs e)
{
If (Request ["err"] = "1 ")
{
Page. RegisterStartupScript ("budget", "<script language = javascript> alert ('upload file has failed! File size is too large! ') </Script> ");
}
}
}
Disadvantage: The file is too large to meet your requirements. For example, if you want to limit to 30 mb, you will find that. An error occurred while uploading 20 mb. Because IIS will assume that you have launched an OS attack. Give your page to Kazuo. In this way, the page will be faulty. Therefore, the best method is to use JS for verification on the client.
Web. config configuration method:
The unit of maxRequestLength is KB.
<? Xml version = "1.0" encoding = "UTF-8"?>
<Configuration>
<System. web>
<HttpRuntime
MaxRequestLength = "1048576" // maximum length
ExecutionTimeout = "3600" // maximum response time.
/>
</System. web>
</Configuration>