开发者

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

开发者 https://www.devze.com 2023-01-10 08:40 出处:网络
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

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开发者_StackOverflow 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...


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.


Check for the value 4096 in Web.Config, under httpRuntime node. Increase it to 100mb or as desired. 4096 means 4mb.

0

精彩评论

暂无评论...
验证码 换一张
取 消