Search code examples
asp.netdebuggingiisasp.net-web-api2http-status-code-400

IIS returning 400 - Missing Content error


I am running IIS version 8.5 on Windows Server 2012 R2. The site is an API handling requests over HTTPS (TLS 1.2). One of the endpoints accepts JSON serialized data via PUT (command/verb). Data can be transferred successfully up to a certain size which is around 8MB. For Data sets larger than that, the client receives a strange HTTP error: 400 - Missing Content. I have enabled tracing rule on the IIS server for the 400 error and it can be seen at what point in the trace that the 400 - Missing Content response is sent back. However, I am unable to decipher what could be going wrong in the events prior to that. All I can notice that the data is being read in chunks of 16299 bytes for a number of rounds. And then all of a sudden the number of bytes read is less (12506 bytes) and we get this sequence of events:

1288.   NOTIFY_MODULE_COMPLETION    ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", CompletionBytes="12506", ErrorCode="The operation completed successfully.
 (0x0)" 07:20:18.730
1289.   AspNetPipelineEnter Data1="System.Web.ImplicitAsyncPreloadModule"   07:20:18.730
1290.   AspNetPipelineLeave Data1="System.Web.ImplicitAsyncPreloadModule"   07:20:18.730
1291.   AspNetHttpHandlerEnter      07:20:18.730
1292.   GENERAL_SET_RESPONSE_HEADER HeaderName="Content-Length", HeaderValue="30", Replace="false"  07:20:19.043
1293.   GENERAL_SET_RESPONSE_HEADER HeaderName="Cache-Control", HeaderValue="private", Replace="true"   07:20:19.043
1294.   GENERAL_SET_RESPONSE_HEADER HeaderName="X-AspNet-Version", HeaderValue="4.0.30319", Replace="true"  07:20:19.043
1295.   MODULE_SET_RESPONSE_ERROR_STATUS
Warning ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="400", HttpReason="missing content", HttpSubStatus="0", ErrorCode="The operation completed successfully.
 (0x0)", ConfigExceptionInfo=""

I have also enabled detailed error response from IIS towards the client but, the returned message does not contain anything useful (just enable tracing which i have already done). Here is a snippet of what is returned in case someone is wondering:

<div class="content-container"> 
  <h3>HTTP Error 400.0 - missing content</h3> 
  <h4>Bad Request</h4> 
</div> 
<div class="content-container"> 
 <fieldset><h4>Most likely causes:</h4> 
  <ul>  <li></li> </ul> 
 </fieldset> 
</div> 
<div class="content-container"> 
 <fieldset><h4>Things you can try:</h4> 
  <ul>  <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>. </li> </ul> 
 </fieldset> 
</div>

Would anyone know what could be the cause of this? Or, what kind of debugging approach i could undertake in order to get more insights in the problem?


Solution

  • After re-examining the configuration of the deployed IIS, it became clear that the problem was due to the fact that the limits on maximum data that can be set by the request. So, there was a mistake (too low value) in MaxRequestLength of the HttpRuntimeSection of the IIS configuration.

    You can read more about this property here: https://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength(v=vs.110).aspx. Essentially, the amount (measure in units of Kilobytes) determines the maximum size of the request. In the above case, when the size of data exceeded the limit set by that field, the problem arose.