Display custom error page when file upload exceeds allowed size in ASP.NET MVC2

Posted by Marcus on Stack Overflow See other posts from Stack Overflow or by Marcus
Published on 2010-05-03T15:36:10Z Indexed on 2010/05/03 15:48 UTC
Read the original article Hit count: 525

Filed under:
|
|

Hello!

My main issue is that I want to display an custom error page when an uploaded file exceeds allowed size (maxRequestLength in web.config).

When the big file is uploaded an HttpException is thrown before my upload action method in the controller is invoked. This is expected.

I have tried to catch the exception in a custom attribute and also to override OnException in the controller. Why isnt it possible to catch the exception in either the attribute or the OnException method?

Its possible though to catch the exception in Application_Error in global.asax but neither Response.Redirect nor Server.Transfer works for redirecting to the custom error page. Server.Transfer gives the "failed to process child request" error and response.redirect gives the "Http headers already sent" error.

Any ideas?

Thanks in advance!

Marcus

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET