我该如何处理的maxRequestLength异常优雅? [英] How can I handle maxRequestLength exceptions elegantly?

查看:247
本文介绍了我该如何处理的maxRequestLength异常优雅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET MVC(V2,如果它事项)的应用程序,我有一个页面,允许用户上传的文件。我已经配置了maxRequestLength的我的应用程序,从而允许文件达到25MB。作为测试,我送它会抛出异常的500MB文件:(我只知道这是因为ELMAH捕获错误,并将其记录)超过最大请求长度

In my ASP.NET MVC (v2 if it matters) app, I have a page that allows the user to upload a file. I've configured the maxRequestLength for my app to allow files up to 25MB. As a test, I send it a 500MB file which throws the exception: Maximum request length exceeded. (I only know this because ELMAH catches the error and logs it.)

在我的web.config,我给自己定的customErrors模式=ON的defaultRedirect ,但用户未在所有的重定向,他们甚至不得到黄屏幕的死亡。在Chrome浏览器,例如,你会看到错误:错误101(净值:: ERR_CONNECTION_RESET):未知的错误

In my web.config, I've set customErrors mode="On" with a defaultRedirect, but the user isn't redirected at all, they don't even get a yellow-screen-of-death. In Chrome, for example, you'll see the error: Error 101 (net::ERR_CONNECTION_RESET): Unknown error.

是否有可能提供这种局面一个更优雅的用户体验?

Is it possible to provide a more elegant user experience for this situation?

推荐答案

据我所知,是没有办法来妥善地处理超过IIS的maxRequestLength的设置。它甚至不能显示自定义错误页(因为没有相应的HTTP code响应)。解决这个问题的唯一方法是设置了maxRequestLength一些荒谬的大量字节,比如51200(50MB),然后检查CONTENTLENGTH该文件已被上传后(假设请求90秒之前没有超时)。在这一点上,我可以确认,如果该文件< = 5MB,并显示一个友好的错误

To my knowledge, there is no way to gracefully handle exceeding IIS's "maxRequestLength" setting. It can't even display a custom error page (since there is no corresponding HTTP code to respond to). The only way around this is to set maxRequestLength to some absurdly high number of kbytes, for example 51200 (50MB), and then check the ContentLength after the file has been uploaded (assuming the request didn't time out before 90 seconds). At that point, I can validate if the file <=5MB and display a friendly error.

这篇关于我该如何处理的maxRequestLength异常优雅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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