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

与世无争的帅哥 提交于 2019-12-12 01:32:52

问题


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...


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3426864/asyncfileupload-how-do-i-hide-the-max-request-length-exceeded-alert-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!