Upload Large File In asp.net or website in Windows Azure .

來源:互聯網
上載者:User

What is the approch of Upload file in asp.net used to do.

The answer is using a Form to upload file . you can use the form and file http element . and you also can work with the asp.net ui component. like HtmlInputFile.

When you try to use the HtmlInputFile control to upload a large file, the file may not be uploaded.

This problem occurs because the default value for the maxRequestLength parameter in the <httpRuntime> section of the Machine.config file is 4096 (4 megabytes). As a result, files that are larger than this value are not uploaded by default.

To resolve this problem, use one of the following methods:

  • In the Machine.config file, change the maxRequestLength attribute of the <httpRuntime> configuration section to a larger value. This change affects the whole computer.
  • In the Web.config file, override the value of maxRequestLength for the application. For example, the following entry in Web.config allows files that are less than or equal to 8 megabytes (MB) to be uploaded:
    <httpRuntime maxRequestLength="8192" />

By default, this value is restricted to 4 MB to restrict possible Denial of Service attacks.

When the maxRequestLength attribute is set in the Machine.config file and then a request is posted (for example, a file upload) that exceeds the value of maxRequestLength, a custom error page cannot be displayed. Instead, Microsoft Internet Explorer will display a "Cannot find server or DNS" error message. 

Theoretically, the maximum file upload size is fairly large. However, because of ASP.NET health monitoring, you cannot upload very large files in ASP.NET. The ASP.NET worker process has a virtual address space of 2 gigabytes (GB). However, the ASP.NET worker process only uses a little more than 1 GB because of health monitoring and memory fragmentation. 

During the upload process, ASP.NET loads the whole file in memory before the user can save the file to the disk. Therefore, the process may recycle because of the memoryLimit attribute of the processModel tag in the Machine.config file. The memoryLimit attribute specifies the percentage of physical memory that the ASP.NET worker process can exhaust before the process is automatically recycled. Recycling prevents memory leaks from causing ASP.NET to crash or to stop responding. 

Additionally, other factors play a role in the maximum file size that can be uploaded. These factors include available memory, available hard disk space, processor speed, and current network traffic. With regular traffic of files being uploaded, Microsoft recommends that you use a maximum file size in the range of 10 to 20 megabytes (MB). If you rarely upload files, the maximum file size may be 100 MB. 

Note You can upload files that are larger than 100 MB in ASP.NET. However, Microsoft recommends that you follow the maximum file upload sizes that are mentioned in this article. To determine more precise file sizes, perform stress testing on computers that are similar to the ones that will be used in production. 

You may notice the following error messages if you encounter file size limits during the file upload process:

  • The page cannot be displayed.
  • Server Application is Unavailable

    In the event log, the error message will be similar to the following:

    aspnet_wp.exe (PID:PIDNumber) was recycled because memory consumption exceeded the SizeLimit MB (Percentagepercent of available RAM).

  • Exception of type System.OutOfMemoryException was thrown.


You may also find that uploads occur very slowly. If you watch the Aspnet_wp.exe process in Windows Task Manager, you will notice that the memory delta changes by 64 KB every 1 to 2 seconds. Depending on the size of the file, this delay may cause the ASP.NET worker process to recycle because of a responseDeadlock error.

 

 

Increasing the maxRequestLength and maxAllowedContentLength

If you’re uploading large files, you'll need to increasing the maxRequestLength setting in ASP.NET which is kept at 4MB by default. The following setting in Web.config should do the trick to increase it to 2GB.

 

<system.web>     <httpRuntime maxRequestLength="2097152"/> </system.web>

 

<system.webServer>       <security>           <requestFiltering>              <requestLimits maxAllowedContentLength="2097152" />           </requestFiltering>       </security> </system.webServer>

 

 

see also :

http://blogs.msdn.com/b/kwill/archive/2011/07/18/how-to-increase-the-size-of-the-windows-azure-web-role-asp-net-temporary-folder.aspx

http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.aspx(httppostfile) 

http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx(expect 100)

http://www.bauer-martin.com/csharp/windows-azure-use-block-blobs-to-upload-large-files-bit-by-bit-802.html(upload file to blob or blockblob) 

http://www.dotnetcurry.com/ShowArticle.aspx?ID=803(upload file to blob in asp.net) 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.