AsyncFileUpload: How do I hide the max request length exceeded alert error?

Carter picture Carter · Aug 6, 2010 · Viewed 8.1k times · Source

If I upload a file that is larger than the configs max request length I get a "Server Response Error: Unknown Server Error" alert popup. It asks if I want to see the response page and if I click "OK" an application error window pops up saying "Maximum request length exceeded."

I found this already... Catching "Maximum request length exceeded"

I was unsuccessful at getting that to work.

I also found another SO question (I can't seem to find it now) that was similar. The difference was that the OP had asked how to redirect to an error page. I don't want to do that. The answer was to use a custom error redirect that gets setup in the web.config.

I simply want to absorb the error and do nothing, I'm using the OnClientUploadError event to handle the error via js. Basically, I just don't want this stupid popup message.

One odd thing is that I don't see the error when running the app locally, but I do see the error when I've got the app deployed out to our server.

Note I should have mentioned that I know about the config value to set the max request length. Setting it to be very large won't work for this instance.

Update So, I'm wondering if this could be something with the IIS settings of our server. It's odd that it doesn't happen locally. Any ideas of what I should be looking for? Most of what I find on the net suggests modifying the machine.config. However, as I said before, I don't simply want to up the allowed size. I am handling the error fine via js, I don't want this alert to show up under any circumstances.

Update Well, it sounds like the IIS default limit is 30MB. The files I'm trying are much less than this. I'm at a loss...

Answer

dhinesh picture dhinesh · Nov 4, 2010

On the OnClientUploadError write javascript which will set some flag and then that flag can be used while submitting the form giving the user the message that the upload caused error.

<asp:AsyncFileUpload ID="fileUpload" 
                     runat="server" OnClientUploadError="onUploadError"
                     OnClientUploadComplete="uploadComplete"
                     OnUploadedComplete="OnUploadComplete" />

in javascript

 <script language="javascript" type="text/javascript">
     var uploadError = false;    
     function onUploadError()
     {
          uploadError = true;
     }

     function uploadComplete()
     {
          uploadError = false;
     }

     function validateForm()
     {
         return !uploadError;
     }
 </script>

By doing this redirection to error page is avoided.