Modify the webcong file:
<System. Web>
& Lt; httpruntime maxrequestlength = "40690"
Usefullyqualifiedredirecturl = "true"
Executiontimeout = "6000"
Usefullyqualifiedredirecturl = "false"
Minfreethreads = "8"
Minlocalrequestfreethreads = "4"
Apprequestqueuelimit = "100"
Enableversionheader = "true"
/>
</System. Web>
Which is closely related to upload:
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 ).
Executiontimeout
Indicates the maximum number of seconds allowed to execute a request before it is automatically disabled by ASP. NET.
The Unit is seconds. When uploading a large file, this setting is larger.
If the server memory is 512 MB, files with a size of MB can be uploaded. (I have never tried it. Comments from all the posts on csdn .)
'
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 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> ");
}
}
}
6. Close the job. (This fish is not white)
After the above modification, the current upload is changed,ProgramSpecifies the file size. If the file size exceeds, an error message is displayed.
In this way, it is much better. At least I can accept it myself, and it is not difficult to explain it to users.
After traversing all the posts about uploading large files in csdn, I wrote this piece of garbage. (:-))
There are several ways to upload large files:
1. The thought httpworkerrequest method is too difficult to understand :-(
2. Use the third-party control aspnetupload for money !! Forget it. We still like free.
3. Modify the Web. config file, but the error cannot be captured.
4. Upload through FTP. The server must provide the FTP service.
No. You have to choose the third method. Who made me stupid! (It's too stupid. It doesn't matter. If you want to eat more fish, I heard that fish can be smarter .)
So study the third method carefully!
Modify the webcong file:
<System. Web>
& Lt; httpruntime maxrequestlength = "40690"
Usefullyqualifiedredirecturl = "true"
Executiontimeout = "6000"
Usefullyqualifiedredirecturl = "false"
Minfreethreads = "8"
Minlocalrequestfreethreads = "4"
Apprequestqueuelimit = "100"
Enableversionheader = "true"
/>
</System. Web>
Which is closely related to upload:
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 ).
Executiontimeout
Indicates the maximum number of seconds allowed to execute a request before it is automatically disabled by ASP. NET.
The Unit is seconds. When uploading a large file, this setting is larger.
If the server memory is 512 MB, files with a size of MB can be uploaded. (I have never tried it. Comments from all the posts on csdn .)
'
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> ");
}
}
}