如何知道当前请求超过 ASP.Net 中的 maxRequestLength?

发布于 2024-08-06 03:22:03 字数 546 浏览 2 评论 0原文

我正在使用 VS2008 和 C# 3.0 在 ASP.Net(框架版本 3.5)中开发一个小型 Web 应用程序。有一个文件上传,我想确保整个请求不超过 5 MB。

我配置了 web.config 文件并且 maxRequestLength 设置正确。

我正在重写页面的 OnError 方法。

但是,在调查异常时,除了实际标识“超出最大请求长度”错误的字符串文字和错误代码之外,我没有看到任何其他内容。我所拥有的只是错误代码(实际的 HResult)和堆栈跟踪。 此处也对此进行了讨论。

这有点问题,因为框架的实现可能在与我不同的操作系统上有所不同:我的开发机器是Windows Server 2008,目标机器可能是Windows 2000/2003/2008 Server。

换句话说,是否有一种可移植的方法来确定当前错误为“超出最大请求长度”?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神回复 2024-08-13 03:22:03

我认为您将不得不求助于带有 JavaScript 的客户端解决方案或使用 Flash/Silverlight 上传控件,它也可以检查客户端文件的大小。

因为当您使用内置的 ASP.NET 检查时,很难捕获这个特定的异常。但是,您可以在发生这种情况时显示友好的错误页面。

http://www.codeplex.com/SLFileUpload

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文