IIS防爆preSS 8 - 最大允许长度 [英] IIS Express 8 - Max allowed length

查看:459
本文介绍了IIS防爆preSS 8 - 最大允许长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在情况下,下面是太长了,我的问题是在Visual Studio 2013的IIS防爆preSS 8是否服从 maxAllowedContentLength 属性,或者如果它有一些更重要的价值即prevents的大型请求


在对调试的Visual Studio 2013的一些的WebAPI电话,我收到此错误:

超过最大请求长度。

我在网上搜索,一切似乎是指向这两个配置项:

  IIS 6:的maxRequestLength
IIS 7+:maxAllowedContentLength

我添加了这两种配置项,以我的web.config与4294967295值,只是为了安全起见。当我尝试拨打电话到控制器,我仍然收到错误。

这让我觉得我会发送一些数据量庞大的服务器,但提琴手告诉我:

 请求次数:1
发送的字节数:4327084(标题:1026;机身:4326058)
接收的字节数:3808(头:434;机身:3,374)

和看到如何,4327084< 4,294,967,295我觉得不应该有这个请求的任何问题。

我想寻找下一个地方是我的服务器code:

 如果(!Request.Content.IsMimeMultipartContent())
{
    抛出新的Htt presponseException(的HTTPStatus code.UnsupportedMediaType);
}VAR提供商=新MultipartFormDataStreamProvider(@C:\\ tmp目录,Int32.MaxValue);VAR任务= Request.Content.ReadAsMultipartAsync(供应商).ContinueWith(T =>
{
    如果(t.IsFaulted || t.IsCanceled)
        扔t.Exception; //< ==这被抛出

所以再次,请求的大小大于缓冲区的大小为数据流提供者显著以下。

因此​​,在总结,我不知道发生了什么事情。该请求是相当大的,但是从我所知道的,我们没有理由这应该是失败的。这是造成VS13 / IIS Exp8?还是有别的东西我失踪?

预先感谢您可以提供任何帮助。


这里的config条目我说我会提供

 < requestLimits maxAllowedContentLength =4294967295/>


这是完整的例外

  System.IO.IOException:错误读取MIME多正文部分。 ---> System.Web.HttpException:超过最大请求长度。
   在System.Web.HttpBufferlessInputStream.ValidateRequestEntityLength()
   在System.Web.HttpBufferlessInputStream.Get preloadedContent(字节[]缓冲区的Int32&安培;偏移的Int32&放大器;计数)
   在System.Web.HttpBufferlessInputStream.BeginRead(字节[]缓冲区,偏移的Int32,算的Int32,AsyncCallback的回调,对象的状态)
   在的System.IO.Stream< BeginEndReadAsync> b__d(流流,ReadWriteParameters ARGS,AsyncCallback的回调,对象的状态)
   在System.Threading.Tasks.TaskFactory`1.FromAsyncTrim [TInstance,TArgs](TInstance thisRef,TArgs ARGS,Func`5 beginMethod,Func`3 endMethod)
   在System.IO.Stream.BeginEndReadAsync(字节[]缓冲区,偏移的Int32,的Int32计数)
   在System.IO.Stream.ReadAsync(字节[]缓冲区,偏移的Int32,的Int32计数的CancellationToken的CancellationToken)
   在System.Web.Http.WebHost.SeekableBufferedRequestStream< ReadAsync> d__0.MoveNext()
---从previous位置堆栈跟踪,其中引发异常的结尾---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
   在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   在System.Net.Http.HttpContentMultipartExtensions< MultipartReadAsync> d__8.MoveNext()
   ---内部异常堆栈跟踪的结尾---
   在System.Net.Http.HttpContentMultipartExtensions< MultipartReadAsync> d__8.MoveNext()
---从previous位置堆栈跟踪,其中引发异常的结尾---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
   在System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   在System.Net.Http.HttpContentMultipartExtensions< ReadAsMultipartAsync> d__0`1.MoveNext()
---从previous位置堆栈跟踪,其中引发异常的结尾---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
   在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   在BICWeb.webservices.controllers.FormsDesignerController<邮政和GT; d__b.MoveNext()在C:\\ code \\ BIC_CORE \\行李箱\\ BIC的\\ src \\ BICWeb \\ web服务\\ \\控制器FormsDesignerController.cs:300线


而内部异常

  System.Web.HttpException(0X80004005):超过最大请求长度。
   在System.Web.HttpBufferlessInputStream.ValidateRequestEntityLength()
   在System.Web.HttpBufferlessInputStream.Get preloadedContent(字节[]缓冲区的Int32&安培;偏移的Int32&放大器;计数)
   在System.Web.HttpBufferlessInputStream.BeginRead(字节[]缓冲区,偏移的Int32,算的Int32,AsyncCallback的回调,对象的状态)
   在的System.IO.Stream< BeginEndReadAsync> b__d(流流,ReadWriteParameters ARGS,AsyncCallback的回调,对象的状态)
   在System.Threading.Tasks.TaskFactory`1.FromAsyncTrim [TInstance,TArgs](TInstance thisRef,TArgs ARGS,Func`5 beginMethod,Func`3 endMethod)
   在System.IO.Stream.BeginEndReadAsync(字节[]缓冲区,偏移的Int32,的Int32计数)
   在System.IO.Stream.ReadAsync(字节[]缓冲区,偏移的Int32,的Int32计数的CancellationToken的CancellationToken)
   在System.Web.Http.WebHost.SeekableBufferedRequestStream< ReadAsync> d__0.MoveNext()
---从previous位置堆栈跟踪,其中引发异常的结尾---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
   在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   在System.Net.Http.HttpContentMultipartExtensions< MultipartReadAsync> d__8.MoveNext()


解决方案

让我们来看看code抛出:

 私人无效ValidateRequestEntityLength()
{
    如果(this._disableMaxRequestLength&安培;!及(this.Length> this._maxRequestLength))
    {
        如果(!(this._context.WorkerRequest是IIS7WorkerRequest))
        {
            this._context.Response.CloseConnectionAfterError();
        }
        抛出新的HttpException(SR.GetString(Max_request_length_exceeded),空,0xbbc);
    }
}

的构造函数设置这些选项:

 内部HttpBufferlessInputStream(HttpContext的背景下,布尔persistEntityBody,布尔disableMaxRequestLength)
{
    this._context =背景;
    this._persistEntityBody = persistEntityBody;
    this._disableMaxRequestLength = disableMaxRequestLength;
    HttpRuntimeSection的httpRuntime = RuntimeConfig.GetConfig(this._context).HttpRuntime;
    this._maxRequestLength = httpRuntime.MaxRequestLengthBytes;
    this._fileThreshold = httpRuntime.RequestLengthDiskThresholdBytes;
    如果(this._persistEntityBody)
    {
        this._rawContent =新HttpRawUploadedContent(this._fileThreshold,this._context.Request.ContentLength);
    }
    INT CONTENTLENGTH = this._context.Request.ContentLength;
    this._remainingBytes =(CONTENTLENGTH大于0)? CONTENTLENGTH:0x7FFFFFFF的;
    this._length = CONTENTLENGTH;
}

和您可以使用此的Htt prequest 功能禁用限制:

 公共流GetBufferlessInputStream(布尔disableMaxRequestLength)
{
    返回this.GetInputStream(假,disableMaxRequestLength);
}

如果你想知道的字节限制是如何被计算,反编译 httpRuntime.MaxRequestLengthBytes

In case the below is too long, my question is whether IIS Express 8 in Visual Studio 2013 obeys the maxAllowedContentLength attribute or if it has some overriding value that prevents large requests


When debugging some webapi calls against Visual Studio 2013, I'm receiving this error:

Maximum request length exceeded.

I searched the internet and everything seems to be pointing to these two config entries:

IIS 6-: maxRequestLength
IIS 7+: maxAllowedContentLength

I've added both these config entries to my web.config with a value of 4294967295, just to be safe. When I try to make the call to the controller, I still receive the error.

This made me think that I was sending some gigantic amount of data to the server, but fiddler tells me this:

Request Count:   1
Bytes Sent:      4,327,084      (headers:1,026; body:4,326,058)
Bytes Received:  3,808      (headers:434; body:3,374)

And seeing as how, 4,327,084 < 4,294,967,295 I feel like there shouldn't be any problems with this request.

The next place I thought of looking is my server code:

if (!Request.Content.IsMimeMultipartContent())
{
    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}

var provider = new MultipartFormDataStreamProvider(@"C:\tmp", Int32.MaxValue);

var task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith(t =>
{
    if (t.IsFaulted || t.IsCanceled)
        throw t.Exception;   // <== This gets thrown

So once again, the size of the request is significantly less than the buffer size for the data stream provider.

So in summary, I have no idea what's going on. The request is fairly big, but from what I can tell, there's no reason this should be failing. Is this caused by VS13/IIS Exp8? Or is there something else I'm missing?

Thanks in advance for any help you can offer.


Here's the config entry I said I would provide

<requestLimits maxAllowedContentLength="4294967295" />


And here's the full exception

System.IO.IOException: Error reading MIME multipart body part. ---> System.Web.HttpException: Maximum request length exceeded.
   at System.Web.HttpBufferlessInputStream.ValidateRequestEntityLength()
   at System.Web.HttpBufferlessInputStream.GetPreloadedContent(Byte[] buffer, Int32& offset, Int32& count)
   at System.Web.HttpBufferlessInputStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
   at System.IO.Stream.<BeginEndReadAsync>b__d(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
   at System.IO.Stream.BeginEndReadAsync(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Web.Http.WebHost.SeekableBufferedRequestStream.<ReadAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Net.Http.HttpContentMultipartExtensions.<MultipartReadAsync>d__8.MoveNext()
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpContentMultipartExtensions.<MultipartReadAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Http.HttpContentMultipartExtensions.<ReadAsMultipartAsync>d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at BICWeb.webservices.controllers.FormsDesignerController.<Post>d__b.MoveNext() in c:\code\BIC_CORE\TRUNK\BIC\src\BICWeb\webservices\controllers\FormsDesignerController.cs:line 300


And the inner exception

System.Web.HttpException (0x80004005): Maximum request length exceeded.
   at System.Web.HttpBufferlessInputStream.ValidateRequestEntityLength()
   at System.Web.HttpBufferlessInputStream.GetPreloadedContent(Byte[] buffer, Int32& offset, Int32& count)
   at System.Web.HttpBufferlessInputStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
   at System.IO.Stream.<BeginEndReadAsync>b__d(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
   at System.IO.Stream.BeginEndReadAsync(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Web.Http.WebHost.SeekableBufferedRequestStream.<ReadAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Net.Http.HttpContentMultipartExtensions.<MultipartReadAsync>d__8.MoveNext()

解决方案

Let's look at the code that throws:

private void ValidateRequestEntityLength()
{
    if (!this._disableMaxRequestLength && (this.Length > this._maxRequestLength))
    {
        if (!(this._context.WorkerRequest is IIS7WorkerRequest))
        {
            this._context.Response.CloseConnectionAfterError();
        }
        throw new HttpException(SR.GetString("Max_request_length_exceeded"), null, 0xbbc);
    }
}

The ctor sets those options:

internal HttpBufferlessInputStream(HttpContext context, bool persistEntityBody, bool disableMaxRequestLength)
{
    this._context = context;
    this._persistEntityBody = persistEntityBody;
    this._disableMaxRequestLength = disableMaxRequestLength;
    HttpRuntimeSection httpRuntime = RuntimeConfig.GetConfig(this._context).HttpRuntime;
    this._maxRequestLength = httpRuntime.MaxRequestLengthBytes;
    this._fileThreshold = httpRuntime.RequestLengthDiskThresholdBytes;
    if (this._persistEntityBody)
    {
        this._rawContent = new HttpRawUploadedContent(this._fileThreshold, this._context.Request.ContentLength);
    }
    int contentLength = this._context.Request.ContentLength;
    this._remainingBytes = (contentLength > 0) ? contentLength : 0x7fffffff;
    this._length = contentLength;
}

And you can use this HttpRequest function to disable the limit:

public Stream GetBufferlessInputStream(bool disableMaxRequestLength)
{
    return this.GetInputStream(false, disableMaxRequestLength);
}

If you want to know how the byte limit is being computed, decompile httpRuntime.MaxRequestLengthBytes.

这篇关于IIS防爆preSS 8 - 最大允许长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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