How can you know that current request exceeds maxRequestLength in ASP.Net?

青春壹個敷衍的年華 提交于 2019-12-13 06:31:54

问题


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"?


回答1:


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



来源:https://stackoverflow.com/questions/1502371/how-can-you-know-that-current-request-exceeds-maxrequestlength-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!