. NET file upload control using methods modify the Web. config file to upload large files

Source: Internet
Author: User
To modify the Webcong file:

The following is the referenced content:

<system.web> 

Which is closely related to uploading:

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.

Units in seconds, when uploading large files, set this larger.

If the server memory is 512M, the file size 160M can be uploaded. (haven't tried, csdn the unanimous opinion of the public posts. )

The setup of the Web. config is over here.

However, once the upload file size exceeds the file size range of this setting, the following error occurs: The page cannot display the page you want to view is currently unavailable. The site may be experiencing technical problems, or you will need to adjust your browser settings.

Although can not solve, that also want to catch this mistake Ah! What do we do? Because this error is a foreground error raised by the file control, it is not feasible to use Try...catch to capture in the background.

Then thought of using. NET error capture page mechanism to handle. Yes, it is possible.

The following is the referenced content:
1. Set up Web. config First

<customerrors mode= "on"/>

2, create a new error.aspx file, specifically used to catch the wrong.

3. Add page instructions to the foreground page of the ASPX page where the file is uploaded. Errorpage= "Uploaderror.aspx"

4. Add some code in 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 "); The Else//foreground error ex is null {Response.Redirect ("uploadexcel.aspx?err=1");//re-jumps to the upload page, plus the Err parameter is to display the error message}}

5. Display error prompt.

public class Uploadexcel:System.Web.UI.Page {private void Page_Load (object sender, System.EventArgs e) {if (request["E RR "] = =" 1 ") {Page.registerstartupscript (" Budget "," <script language = javascript> alert "(' Upload file has failed! F Ile size is too large! ') </script> "); } } }


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.