Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC: Handling upload exceeding maxRequestLength
    text
    copied!<p>When uploading a file in my MVC site, I'm looking to handle upload failures due to the user exceeding maxRequestLength more gracefully than for example showing a generic custom error page. I would prefer to display the same page they're trying to post to, but with a message informing them that their file was too large... similar to what they might get on a validation error. </p> <p>I'm starting with the idea from this question:</p> <p><a href="https://stackoverflow.com/questions/665453/catching-maximum-request-length-exceeded">Catching &quot;Maximum request length exceeded&quot;</a></p> <p>BUT what I want to do is instead of Transferring to an error page (as they do in that question), I want to hand processing off to the original controller but with an error added to ModelState indicating the issue. Here's some code, with the comments indicating where and what I would like to do. See the question above for definition of IsMaxRequestExceededEexception, which is a bit of a hack, but I haven't found much better.</p> <p>The line I've commented out returns the user to the right page, but of course they lose any changes they may have made and I don't want to use Redirect here...</p> <pre><code>if (IsMaxRequestExceededException(Server.GetLastError())) { Server.ClearError(); //((HttpApplication) sender).Context.Response.Redirect(Request.Url.LocalPath + "?maxLengthExceeded=true"); // TODO: Replace above line - instead tranfer processing to appropriate controlller with context intact, etc // but with an extra error added to ModelState. } </code></pre> <p>Just looking for ideas rather than a full solution; is what I'm trying to do is even possible?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload