Upload large file in Asp.net or website in Windows azure.

Source: Internet
Author: 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 useHtmlinputfileControl to upload a large file, the file may not be uploaded.

This problem occurs because the default value forMaxrequestlengthParameter in<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, changeMaxrequestlengthAttribute of<Httpruntime>Configuration section to a larger value. This change affects the whole computer.
    • In the Web. config file, override the valueMaxrequestlengthFor 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.

WhenMaxrequestlengthAttribute is set in the machine. config file and then a request is posted (for example, a file upload) that exceeds the valueMaxrequestlength, 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. reconfiguring 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.

NoteYou 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 exceededSizelimitMB (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 4 MB by default. the following setting in web. config shoshould do the trick to increase it to 2 GB.

 

 
<System. Web><HttpruntimeMaxrequestlength= "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

A 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 (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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.