2011-01-25 68 views
0

當上傳長度超過配置的maxRequestLength時,在文件上載過程中,IIS當前正在執行的請求真的發生了什麼。 試圖很難找到一個體面的文章,談論這一點,但沒有!maxRequestLength - 需要幕後細節!

感謝

+0

喲喲你是什​​麼意思?拋出的異常是什麼發生。 – 2011-01-26 10:05:38

回答

2

這到底發生了什麼:

HttpRequest類和方法GetEntireRawContent這種情況下被選中,將拋出一個異常:

if (length > maxRequestLengthBytes) 
{ 
    throw new HttpException(System.Web.SR.GetString("Max_request_length_exceeded"), null, 0xbbc); 
} 

這裏是整個方法如果你覺得有用:

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

爲什麼它使用applicationInstance.EntityBuffer來緩衝ReadEntityBody的讀取。這不會導致線程問題嗎?或者IIS是否連續處理這些請求? – Triynko 2012-10-03 23:11:11