Sunday, October 28, 2007

Things to consider while uploading files using ASP.NET

While uploading data using ASP.NET application we need to take care of the size of data. If the original settings have not been modified, ASP.NET allows 4096 KB data in request.
To have more data or uploading larger files, one needs to have changes in web.config file. The maxRequestLength attribute of the httpRuntime element can be modified accordingly.
The Machine.config file may also have the maxRequestLength attribute. In such case, custom error pages cannot be displayed, instead IE displays error page “Cannot find server or DNS”.
Following are the default values of attributes in Machine.config file:

httpruntime executiontimeout="90"
maxrequestlength="4096"
usefullyqualifiedredirecturl="false"
minfreethreads="8"
minlocalrequestfreethreads="4"
apprequestqueuelimit="100"

Note: The Machine.config file is located in the \System Root\Microsoft.NET\Framework\Version Number\CONFIG directory.
ADDITIONAL INFORMATION
The ASP.NET worker process has virtual address space of 2 GB but it uses somewhat more than 1 GB because health monitoring and memory fragmentation. During file upload process, ASP.NET loads the whole file in memory before saving to disk. We can specify value of memoryLimit attribute of the processModel tag. The value is percentage of physical memory that ASP.NET worker process can exhaust before the process automatically recycled. Recycling prevents memory leaks from causing ASP.NET to crash or to stop responding.
Other things to consider while uploading file are available memory, available hard disk space, network traffic and processor speed. The recommended maximum file size is in range of 10 to 20 MB.
Following error messages can be noticed during large 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 (Percentage percent 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.

1 comment:

  1. Great man ,,,,,this blog has been resolved my problem so thank you again

    ReplyDelete