当达到文件限制时如何获取错误? Plupload + asp.net mvc 3 +网络配置

发布于 2024-11-04 15:44:37 字数 725 浏览 0 评论 0原文

我正在玩 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 技术交流群。

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

发布评论

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

评论(1

风苍溪 2024-11-11 15:44:37

You may take a look at the following blog post which suggests handling this exception in the Application_Error method.

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