Asp.net中,上傳檔案的預設大小是4096 KB,也就是4M,不過你可以在Web.config中更改這個資料
<httpRuntime maxRequestLength="10240"
useFullyQualifiedRedirectUrl="true"
executionTimeout="100"/>
那麼此時就是10M的檔案,當然你也可以把它修改的更大,但是不管改成多大都會有個極限,如果使用者上傳的檔案比這個值大,就會出現程式Catch不到的異常,因為這個是在運行時才能夠監測,如下的錯誤:
Action canceled |
|
Internet Explorer was unable to link to the Web page you requested. The page might be temporarily unavailable. |
Please try the following:
- Click the Refresh button, or try again later.
- If you have visited this page previously and you want to view what has been stored on your computer, click File, and then click Work Offline.
- For information about offline browsing with Internet Explorer, click the Help menu, and then click Contents and Index.
|
雖然你在代碼中控制了大小,不過程式在運行到這裡之前已經崩潰了
// Attachment size is too larger
if(PersonPhoto.PostedFile.ContentLength > 10240)
{
this.lblError.Text = "The file you selected is larger than 10MB";
this.lblError.Visible = true;
return;
}
大家有什麼辦法嘛?