Asp. NET to set the size method of uploading files in Web.config __web

Source: Internet
Author: User
Tags time limit server memory
ASP. NET sets the size of the upload file in web.config To modify the Webcong file:
<system.web>
Usefullyqualifiedredirecturl= "true"
executiontimeout= "6000"
Usefullyqualifiedredirecturl= "false"
Minfreethreads= "8"
Minlocalrequestfreethreads= "4"
apprequestqueuelimit= "100"
Enableversionheader= "true"
/>
</system.web>
Which is closely related to the upload is:
If the server memory is 512M, you can upload files of size 160M.
Webconfig Configure Connection Timeout
<!--
Executiontimeout= "90" to Executiontimeout= "720" by WP 2007.9.4 EXECUTIONTIMEOUT indicates the maximum time limit to allow execution of the request, in seconds
maxRequestLength: Indicates the maximum file upload size supported by asp.net. The specified size is in kilobytes. The default value is 4096 KB (4 MB).
-->

<!--
HttpRuntime is to configure the ASP.net HTTP run-time settings to determine how to handle requests for asp.net applications.
Executiontimeout: Represents the maximum time limit, in seconds, that a request is allowed to execute
maxRequestLength: Indicates the maximum file upload size supported by asp.net. This restriction can be used to prevent denial of service attacks caused by a user passing a large number of files to the server. The specified size is in kilobytes. The default value is 4096 KB (4 MB).
useFullyQualifiedRedirectUrl: Indicates whether client redirection is fully qualified (with the
Http://server/path"format, which is required for some mobile controls, or whether to send relative redirection to the client instead. If true, all redirects that are not fully qualified are automatically converted to fully qualified formats. False is the default option.
minFreeThreads: Specifies the minimum number of free threads that are allowed to execute new requests. asp.net the specified number of threads to maintain a free State for requests that require additional threads to complete their processing. The default value is 8.
minLocalRequestFreeThreads: Represents the minimum number of free threads that the ASP.net maintains to allow the execution of new local requests. The number of threads is reserved for requests that are passed in from the local host in case some requests issue a child request to the local host during its processing. This avoids a possible deadlock caused by recursion to re-enter the WEB server.
appRequestQueueLimit: Represents the maximum number of requests that ASP.net will queue for an 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.
Enableversionheader: Indicates whether the specified asp.net should output a version header. Microsoft Visual Studio 2005 uses this property to determine which version of ASP.net is currently in use. For a production environment, this property is not required and can be disabled.
The setting of the web.config here is over.
However, once the size of the uploaded file exceeds the file size of this setting, the following error occurs:
The page cannot be displayed
The page you are looking for is currently unavailable. Your web site may be experiencing technical problems, or you need to adjust your browser settings.
Though it can't be solved, it must catch the mistake. How to do it.
Recently ate a few fish, think about, because this error is caused by the file control foreground error, so in the background want to use Try...catch to capture is not feasible.
So I thought of using. NET error capture page mechanism to deal with. Yes, it works.
1, first set web.config
<customerrors mode= "on"/>
2, create a new error.aspx file, specifically to catch the wrong.
3. Add page directives to the front page of the ASPX page of the uploaded file. Errorpage= "Uploaderror.aspx"
4. Add some code in the error.aspx to determine if the error message is a foreground error caused by file.
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"); Re-jump to upload page, plus err parameter to display error message
}
}
5, display error prompts.
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: A file that is too large may not be up to your requirements. Like you want to limit to 30M, but you'll find. When you upload 20M, you make a mistake. Because IIS will think you have an OS attack. You clicked the page. There will be problems with the page. So the best way is to use JS in the client to verify.
Web.config configuration method:
maxRequestLength units are KB
<?xml   version= "1.0"    encoding= "Utf-8"   ?>
<configuration>
    <system.web>
                      maxrequestlength= "1048576"   //Maximum length
             executiontimeout= "3600"   //maximum response time.
       />
    </system.web>
</ Configuration>

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.