您如何知道当前请求超过ASP.Net中的maxRequestLength? [英] How can you know that current request exceeds maxRequestLength in ASP.Net?

查看:85
本文介绍了您如何知道当前请求超过ASP.Net中的maxRequestLength?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我要覆盖页面的OnError方法.

但是,在调查异常时,除了字符串文字和错误代码以外,我什么都看不到,它们实际上标识了超出最大请求长度"错误.我所拥有的只是错误代码(实际的HResult)和堆栈跟踪.还此处进行了讨论.

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

换句话说,是否有一种便携式方式将当前错误确定为超出最大请求长度"?

解决方案

我认为您将不得不使用JavaScript的客户端解决方案或使用Flash/Silverlight上传控件,该控件还可以检查客户端文件的大小.

因为当您使用内置的ASP.NET进行检查时,很难捕获到此特定异常.但是,您可以在发生错误时显示友好的错误页面.

http://www.codeplex.com/SLFileUpload

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

这篇关于您如何知道当前请求超过ASP.Net中的maxRequestLength?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆