IIS Express 8 - Maximum Allowed Length

In case there are too many below, my question is whether IIS Express 8 obeys the attribute in Visual Studio 2013 maxAllowedContentLengthor has some basic meaning that prevents large requests


When debugging some webapi calls against Visual Studio 2013, I get this error:

Maximum request length exceeded.

I searched on the Internet and everything seems to point to these two configuration entries:

IIS 6-: maxRequestLength
IIS 7+: maxAllowedContentLength

I added both of these configuration entries to my web.config with a value of 4294967295 to be safe. When I try to make a controller call, I still get an error message.

This made me think that I was sending some huge amount of data to the server, but the violinist tells me about it:

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

, , , 4,327,084 < 4 294 967 295 , .

, , - :

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

, .

, , . , , , , . VS13/IIS Exp8? - , ?

, .


,

<requestLimits maxAllowedContentLength="4294967295" />

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

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()
+2
2

, :

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);
    }
}

ctor :

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;
}

HttpRequest :

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

, , httpRuntime.MaxRequestLengthBytes.

+2

Source: https://habr.com/ru/post/1618322/


All Articles