views:

246

answers:

1

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.

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
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ı
Yes, from global.asax
er-v
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ı
Is it on your Development Server? try if it work on IIS - just change properties of solution
er-v
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ı