ASP.NET中關於上傳附件的大小設定問題

來源:互聯網
上載者:User

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;

}

大家有什麼辦法嘛?

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.