首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maxRequestLength -幕后细节所需!

maxRequestLength -幕后细节所需!
EN

Stack Overflow用户
提问于 2011-01-26 07:38:48
回答 1查看 514关注 0票数 0

在文件上传期间,当上传长度超过配置的maxRequestLength时,IIS中当前正在执行的请求会发生什么情况。我努力寻找一篇像样的文章谈到这一点,但没有!!

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-26 08:06:48

这就是实际发生的情况:

在类HttpRequest和方法GetEntireRawContent中,此条件被检查并将抛出异常:

代码语言:javascript
复制
if (length > maxRequestLengthBytes)
{
    throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
}

下面是整个方法,如果你觉得有用的话:

代码语言:javascript
复制
    private HttpRawUploadedContent GetEntireRawContent()
    {
        if (this._wr == null)
        {
            return null;
        }
        if (this._rawContent == null)
        {
            HttpRuntimeSection httpRuntime = RuntimeConfig.GetConfig(this._context).HttpRuntime;
            int maxRequestLengthBytes = httpRuntime.MaxRequestLengthBytes;
            if (this.ContentLength > maxRequestLengthBytes)
            {
                if (!(this._wr is IIS7WorkerRequest))
                {
                    this.Response.CloseConnectionAfterError();
                }
                throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
            }
            int requestLengthDiskThresholdBytes = httpRuntime.RequestLengthDiskThresholdBytes;
            HttpRawUploadedContent data = new HttpRawUploadedContent(requestLengthDiskThresholdBytes, this.ContentLength);
            byte[] preloadedEntityBody = this._wr.GetPreloadedEntityBody();
            if (preloadedEntityBody != null)
            {
                this._wr.UpdateRequestCounters(preloadedEntityBody.Length);
                data.AddBytes(preloadedEntityBody, 0, preloadedEntityBody.Length);
            }
            if (!this._wr.IsEntireEntityBodyIsPreloaded())
            {
                int num3 = (this.ContentLength > 0) ? (this.ContentLength - data.Length) : 0x7fffffff;
                HttpApplication applicationInstance = this._context.ApplicationInstance;
                byte[] buffer = (applicationInstance != null) ? applicationInstance.EntityBuffer : new byte[0x2000];
                int length = data.Length;
                while (num3 > 0)
                {
                    int size = buffer.Length;
                    if (size > num3)
                    {
                        size = num3;
                    }
                    int bytesIn = this._wr.ReadEntityBody(buffer, size);
                    if (bytesIn <= 0)
                    {
                        break;
                    }
                    this._wr.UpdateRequestCounters(bytesIn);
                    this.NeedToInsertEntityBody = true;
                    data.AddBytes(buffer, 0, bytesIn);
                    num3 -= bytesIn;
                    length += bytesIn;
                    if (length > maxRequestLengthBytes)
                    {
                        throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
                    }
                }
            }
            data.DoneAddingBytes();
            if ((this._installedFilter != null) && (data.Length > 0))
            {
                try
                {
                    try
                    {
                        this._filterSource.SetContent(data);
                        HttpRawUploadedContent content2 = new HttpRawUploadedContent(requestLengthDiskThresholdBytes, data.Length);
                        HttpApplication application2 = this._context.ApplicationInstance;
                        byte[] buffer3 = (application2 != null) ? application2.EntityBuffer : new byte[0x2000];
                        while (true)
                        {
                            int num7 = this._installedFilter.Read(buffer3, 0, buffer3.Length);
                            if (num7 == 0)
                            {
                                break;
                            }
                            content2.AddBytes(buffer3, 0, num7);
                        }
                        content2.DoneAddingBytes();
                        data = content2;
                    }
                    finally
                    {
                        this._filterSource.SetContent(null);
                    }
                }
                catch
                {
                    throw;
                }
            }
            this._rawContent = data;
        }
        return this._rawContent;
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4800100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档