当达到文件限制时如何获取错误? Plupload + asp.net mvc 3 +网络配置
我正在玩 plupload,我制作了一个 80mb 的大文件,我正在尝试上传它。
plupload 看起来正在上传。它从 0% 开始,一直到 100%。
现在它在服务器上死掉了,原因是因为 web.config 中的默认限制大小是 4mbs,由它控制。
<httpRuntime executionTimeout="240" maxRequestLength="102400" />
当我将其设置为像上面文件上传那样的高数字时,我遇到了断点。如果我没有进行上述设置并上传一个大文件(超过 4mb),它永远不会达到我的操作方法中的断点。
那么我怎样才能告诉我的用户他们已经达到了限制呢?如果我无法进入我的方法,至少返回一条消息。现在他们会认为一切都很好并且已经上传了。
我知道 plupload 确实有检查文件大小的东西,但我将其视为客户端验证,现在我正在尝试进行服务器端验证。
[HttpPost]
public JsonResult Import(HttpPostedFileBase file)
{
// never gets here if file is bigger than the web.config size.
if (ModelState.IsValid)
{
}
}
I am playing around with plupload and I made a huge file that is 80mb and I am trying to upload it.
plupload looks like it is uploading it. It starts at 0% and goes to 100%.
Now it dies at the server and the reason is because the default limit size is like 4mbs in the web.config controlled by this
<httpRuntime executionTimeout="240" maxRequestLength="102400" />
When I set it to a high number like above the file uploads and I hits my break point. If I don't have the above set and upload a large file(over 4mb) It never hit's my break point in my action method.
So how can I tell my users that hey they reached the limit? If I can't get into my methods and at the very least return a message back. Right now they would think that all was well and it uploaded.
I know plupload does have stuff that checks the file size but I treat that like client side validation and now I am trying to do server side validation.
[HttpPost]
public JsonResult Import(HttpPostedFileBase file)
{
// never gets here if file is bigger than the web.config size.
if (ModelState.IsValid)
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以查看以下博客文章< /a> 建议在
Application_Error
方法中处理此异常。You may take a look at the following blog post which suggests handling this exception in the
Application_Error
method.