Few months back, I was in my office enjoying my green tea and reading an article about Brad Pitt and Angelina Jolie, suddenly my mIRC window started blinking, I opened it and to my horror, it was a personal message from one of the QA guys (who was testing my application), he was asking me that ‘is there any size limit on attachments?’ As I hadn’t placed any size constraint, I replied in negative, but I started to have a feeling that a bug is just around the corner and so it happened. He went excited and informed me with great enthusiasm that when he tries to upload a 5 MB file, application shows him a ‘Page Not Found’ error. I asked him to post the bug, then closed the article on the two Hollywood stars and in order to find the reason/solution I turned to my old buddy , ‘Google.’
Within 15 minutes I realized that every second ASP.Net programmer has faced this problem and still there is no good solution to it.
The problem was that by default ASP.Net ‘FileUpload’ control allows files of size 4 MB or less, anything bigger then that size will redirect you to a DNS error. The main reason behind this constraint is to prevent denial of service attack in-case users posts files of extremely large sizes.
The solution was quite simple, in web.config’s element; you just need to set the value of ‘maxRequestLength’ to your desirable maximum file size. easy!
But, it’s not that easy, anything greater then that size will
stillredirect you to DNS error page. We certainly don’t want to let our users see that page, instead we would like to show them a good error message saying something like ‘files size should be less than {0}.’ For your disappointment, I must confess that there is simply no solution to it. You just don’t have any control on the process; no implementation of IHttpHandler can help you in this regard. One of our friend’s on
thislink tried to provide a solution but it just doesn’t work for about 90% of the people (including me). Whenever the file size was largeer than the maximum allowed size, Reques.Files.Count was somehow ‘0.’
Microsoft provides a little bit of
help, which you may access at,
http://support.microsoft.com/default.aspx?scid=kb;en-us;295626Now, that’s not all, there is something more to this problem, ASP.Net uses physical memory to upload a file and whenever ASP.Net process uses 60% of RAM, .Net services restarts. Hopefully, you can appreciate the magnitude of the problem. And to make it a bit more convoluted, IIS has its own file size limit of 4 GB.If you’ve visited the MS link, then you can see that MS knows about the DNS thing, still they are trying to become oblivious to it, so we should read between the lines, that they want us to go for a third part control. Yes, if your expected file size is small then go for this control, otherwise I would recommend you to go for a 3rd party control.
Happy coding!