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 catch it from the action method or controller for upload requests but no luck. Connection is resetted and I can't get it to show an error page.
views:
246answers:
1
A:
You cant catch error in action method becouse exception comes earlier, but you can catch it here
protected void Application_Error() {
var lastError = Server.GetLastError();
if(lastError !=null && lastError is HttpException && lastError.Message.Contains("exceed")) {
Response.Redirect("~/errors/RequestLengthExceeded");
}
}
Actualy when file size exceeds limits HttpException error arise.
There is also IIS limit on content - wich can't be catched in application. IIS 7 throws
HTTP Error 404.13 - Not Found The request filtering module is configured to deny a request that exceeds the request content length.
You can google it, there is a lot of information about this iis error.
er-v
2010-05-03 07:35:24
I haven't hosted it on IIS yet. I'm trying it on development server but I'll keep in mind. I'm assuming I should handle it from global.asax?
Ufuk Hacıoğulları
2010-05-03 10:22:20
Yes, from global.asax
er-v
2010-05-03 10:36:10
It's strange.I manage to catch the error but I can't redirect it somewhere else. It goes for the upload URL. Look like someone else had [the same problem](http://forums.asp.net/p/845691/957981.aspx#957981)
Ufuk Hacıoğulları
2010-05-03 11:22:59
Is it on your Development Server? try if it work on IIS - just change properties of solution
er-v
2010-05-03 11:59:42
Looks like it can't be solved with Application_Error. Somebody managed to do it with BeginRequest event [here](http://www.velocityreviews.com/forums/t97027-how-to-handle-maximum-request-length-exceeded-exception.html)I'm working on it
Ufuk Hacıoğulları
2010-05-03 12:16:03