I'm developing a small web application in ASP.Net (framework version 3.5) using VS2008 and C# 3.0. There's a file upload, and I want to make sure that the whole request doesn't exceed 5 MB.
I configured the web.config file and maxRequestLength is set properly.
I'm overriding the page's OnError method.
However, while investigating the exception, I don't see anything other than string literals and error codes that actually identify the "Maximum request length exceeded" error. All I have is the error code (the actual HResult
) and the stack trace. It is also discussed here.
This is a bit of a problem, because the implementation of the framework might be different on an OS different than mine: my development machine is Windows Server 2008, and the target machine might be Windows 2000/2003/2008 Server.
In other words, is there a portable way to determine current error as "Maximum request length exceeded"?
I think you will have to resort to client side solution with JavaScript or use Flash/Silverlight upload control which also could check the size of the file/files clientside.
Because when you use the builtin ASP.NET's checking it very hard to catch this specific exception. You can, however, display a friendly error page when it happens.
http://www.codeplex.com/SLFileUpload