To modify the Webcong file:
The following are the referenced contents:
Copy Code code as follows:
<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:
Copy Code code as follows:
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).
Copy Code code as follows:
Indicates the maximum number of seconds allowed to execute a request before it is automatically closed by asp.net.
The unit is seconds, and when uploading large files, set this up a bit larger.
If the server memory is 512M, you can upload files of size 160M. (haven't tried, csdn the unanimous opinion of the public posts.) )
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 display that the page you are viewing is currently unavailable. Your web site may be experiencing technical problems, or you need to adjust your browser settings.
Although cannot solve, that also must catch this mistake! What do we do? Because this error is a foreground error caused by the file control, it is not feasible to use Try...catch in the background to capture it.
So I thought of using. NET error capture page mechanism to deal with. Yes, it works.
The following are the referenced contents:
1, first set web.config
Copy Code code as follows:
<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.
Copy Code code as follows:
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,
The Err parameter is added to display an error message
}
}
5, display error prompts.
Copy Code code as follows:
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> ");
}
}
}