Web Forms upload guides
Max File Size Validation for ASP.NET Uploads
A user who selects a 200 MB video into a field meant for a 5 MB document should learn that before the transfer starts. Checking the size in the browser saves bandwidth and gives a clear message. Checking it on the server is still required, because the browser check can be bypassed.
Set the limit on the uploader
MaxFileSize takes a readable value such as 5MB. A file over that size is refused as soon as it is selected, so it never uploads:
<au:AjaxFileUpload ID="Document" runat="server"
MaxFileSize="5MB"
ButtonText="Select File (max 5MB)"
AutoUpload="true"
ShowProgress="true" />
Match the server limit
The browser check only helps if the server accepts the same size. Each layer has its own ceiling: the ASP.NET request limits, IIS request filtering and any proxy in front of the site. If the uploader allows 50 MB and IIS allows 28 MB, a 40 MB file fails after the transfer begins. The large-file upload guide lists the four limits that apply and how to raise them together.
Read the rejection on the server
A file that passes the browser check still needs a server-side check on the stored file. Compare the length of the file the handler received against your own limit before you save it. Do not rely on the client value alone.
Try it
The maximum file size demo uses a 5 MB limit. Select a file larger than 5 MB and watch it refused before any bytes are sent.
Related