How to catch ConfigurationErrorsException for violating maxRequestLength?

后端 未结 5 1577
[愿得一人]
[愿得一人] 2020-12-15 10:26

I am limiting file size users can upload to the site from Web.config. As explained here, it should throw a ConfigurationErrorsException if size is not accepted. I tried to c

5条回答
  •  暖寄归人
    2020-12-15 11:07

    I have a similar issue in that I want to catch the 'Maximum request length exceeded' exception within the Application_Error handler and then do a Redirect.

    (The difference is that I am writing a REST service with ASP.Net Web API and instead of redirecting to an error page, I wanted to redirect to an Error controller which would then return the appropriate response).

    However, what I found was that when running the application through the ASP.Net Development Server, the Response.Redirect didn't seem to be working. Fiddler would state "ReadResponse() failed: The server did not return a response for this request."

    My client (Advanced REST Client for Chrome) would simply show "0 NO RESPONSE".

    If I then ran the application via a local copy of IIS on my development machine then the redirect would work correctly!

    I'm not sure i can definitively say that Response.Redirect does not work on the ASP.Net Development Server but it certainly wasn't working in my situation.

    So, I recommend trying to run your application through IIS instead of IIS Express or the Development Server and see if you get a different result.

    See this link on how to Specify the Web Server for Web Projects in Visual Studio:

    http://msdn.microsoft.com/en-us/library/ms178108(v=vs.100).aspx

提交回复
热议问题