<small id='1ZcmI'></small><noframes id='1ZcmI'>

      <legend id='1ZcmI'><style id='1ZcmI'><dir id='1ZcmI'><q id='1ZcmI'></q></dir></style></legend>
    1. <tfoot id='1ZcmI'></tfoot>
      • <bdo id='1ZcmI'></bdo><ul id='1ZcmI'></ul>
      <i id='1ZcmI'><tr id='1ZcmI'><dt id='1ZcmI'><q id='1ZcmI'><span id='1ZcmI'><b id='1ZcmI'><form id='1ZcmI'><ins id='1ZcmI'></ins><ul id='1ZcmI'></ul><sub id='1ZcmI'></sub></form><legend id='1ZcmI'></legend><bdo id='1ZcmI'><pre id='1ZcmI'><center id='1ZcmI'></center></pre></bdo></b><th id='1ZcmI'></th></span></q></dt></tr></i><div id='1ZcmI'><tfoot id='1ZcmI'></tfoot><dl id='1ZcmI'><fieldset id='1ZcmI'></fieldset></dl></div>

    2. 上传超过 Asp.net 请求长度限制的文件?

      时间:2023-06-02
      • <tfoot id='hbC6I'></tfoot>
      • <legend id='hbC6I'><style id='hbC6I'><dir id='hbC6I'><q id='hbC6I'></q></dir></style></legend>
            <bdo id='hbC6I'></bdo><ul id='hbC6I'></ul>

                <tbody id='hbC6I'></tbody>

                <small id='hbC6I'></small><noframes id='hbC6I'>

              1. <i id='hbC6I'><tr id='hbC6I'><dt id='hbC6I'><q id='hbC6I'><span id='hbC6I'><b id='hbC6I'><form id='hbC6I'><ins id='hbC6I'></ins><ul id='hbC6I'></ul><sub id='hbC6I'></sub></form><legend id='hbC6I'></legend><bdo id='hbC6I'><pre id='hbC6I'><center id='hbC6I'></center></pre></bdo></b><th id='hbC6I'></th></span></q></dt></tr></i><div id='hbC6I'><tfoot id='hbC6I'></tfoot><dl id='hbC6I'><fieldset id='hbC6I'></fieldset></dl></div>
                本文介绍了上传超过 Asp.net 请求长度限制的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我搜索了 SO,发现 这个问题,但这不是我要问的.我想知道是否可以创建一个可以检查请求的 ContentLength 的 IHttpModule,如果可以,则重定向或以某种方式抛出该请求并创建一个新请求.

                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.

                具体来说,我正在尝试处理图像文件上传,但我想让请求继续到上传页面并发出某种警告,而不是一个简单的错误页面.我有这段代码会受到很大的请求:

                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?

                按原样(没有此模块),Fiddler 报告 IIS 正在返回 500 代码.我想避免这种情况,并让代码从请求的页面返回 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.

                推荐答案

                由于 HTTP 的性质,在读取所有请求数据之前,您实际上无法返回任何内容.当您收到超大请求时,您有两种选择:

                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:

                • 读入所有数据,然后返回一个漂亮的错误页面.这听起来不错,但意味着用户必须等待上传完成才能收到他无法上传的消息.它还打开了一个可能的 DOS 攻击漏洞
                • 立即终止请求.这会给用户一个糟糕的断开连接页面,但保留了安全性.

                还有第三种选择——使用一个高级组件,它提供了很好的错误消息和安全性.您可以只使用 Flash 组件,而且其中有很多组件,但是当然,如​​果用户没有 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 请求长度限制的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:文件上传控制不起作用 下一篇:ASP.NET CORE 中的 Request.Files

                相关文章

                最新文章

                • <bdo id='PJ9lJ'></bdo><ul id='PJ9lJ'></ul>
              2. <legend id='PJ9lJ'><style id='PJ9lJ'><dir id='PJ9lJ'><q id='PJ9lJ'></q></dir></style></legend>
                <tfoot id='PJ9lJ'></tfoot>

                <small id='PJ9lJ'></small><noframes id='PJ9lJ'>

                <i id='PJ9lJ'><tr id='PJ9lJ'><dt id='PJ9lJ'><q id='PJ9lJ'><span id='PJ9lJ'><b id='PJ9lJ'><form id='PJ9lJ'><ins id='PJ9lJ'></ins><ul id='PJ9lJ'></ul><sub id='PJ9lJ'></sub></form><legend id='PJ9lJ'></legend><bdo id='PJ9lJ'><pre id='PJ9lJ'><center id='PJ9lJ'></center></pre></bdo></b><th id='PJ9lJ'></th></span></q></dt></tr></i><div id='PJ9lJ'><tfoot id='PJ9lJ'></tfoot><dl id='PJ9lJ'><fieldset id='PJ9lJ'></fieldset></dl></div>