上传文件过去Asp.net要求长度的限制? [英] Uploading files past Asp.net request length limit?

查看:122
本文介绍了上传文件过去Asp.net要求长度的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索SO,发现<一个href=\"http://stackoverflow.com/questions/126167/asp-net-how-to-show-a-error-page-when-uploading-big-file-maximum-request-lengt\">this问题,但它不是我在问什么比较。我想知道,如果一个IHttpModule的,可以创建能够检查请求的CONTENTLENGTH,如果是这样要么重定向或以某种方式出来扔这一请求,并创建一个新的。

I searched SO and found this question, but it's not quite what I'm asking. I'm wondering if a IHttpModule can be created that can inspect the ContentLength of the request, and if so either redirect or somehow throw that request out and create a new one.

具体来说,我想处理的图像文件上传,但我想有要求继续上传页面以某种警告,而不是一个平面的错误页面。我有code,获取了大量请求,触及该位:

Specifically, I'm trying to handle image file uploads, but I'd like to have the request continue on to the upload page with some kind of warning, rather than a flat error page. I have this bit of code that gets hit with a large request:

    private void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;

        if (context.Request.ContentLength > (4 * 1024 * 1024))
        {

        }
    }

执行路径进入该IF块像我想它。但是,从这里,我真的不知道哪里去了。这是一个不好的做法?

The execution path enters this IF block like I want it to. But from here, I'm not really sure where to go. Is this a bad approach?

编辑:由于它是(如果没有这个模块),菲德勒报道说IIS是返回一个500 code。我想避免这种情况,并有code从请求的页面返回200,只是警告就像我说的。

As it is (without this module), Fiddler is reporting that IIS is returning a 500 code. I'd like to avoid this and have the code return a 200 from the requested page, just with the warning like I said.

推荐答案

,你不能真正,直到你读所有的请求数据返回任何东西。当您收到一个超大的请求时,你有两个选择:

Because of the nature of HTTP, you can't actually return anything until you read all the request data. When you receive an oversized request, you have two options:


  • 阅读中的所有数据,然后返回一个不错的错误页面。这听起来不错,但意味着用户必须等待上传完成他得到他不能上传消息之前。它还会打开一个可能的拒绝服务攻击漏洞

  • 立即终止请求。这给用户一个蹩脚的断开页,但preserves安全性。

还有第三个选择 - 采用先进的组件,同时提供很好的错误信息以及安全。您可以使用Flash只能组件,而且有很多人在那里,当然,如果用户不具有闪光灯,你的运气了。

There is a third option -- use an advanced component that provides both nice error messages as well as security. You can use flash only components, and there are many of them out there, but of course, if the user doesn't have flash, you're out of luck.

这篇关于上传文件过去Asp.net要求长度的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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