Search code examples
.netiisiis-express

How to stop IIS Express 10.0 returning 411 LengthRequired


I have a .NET 4.6.1 client application that uses HttpWebRequest to call a WebAPI hosted on IIS. One of the calls is a POST request without a body that does not set the ContentLength header (HttpWebRequest.ContentLength has its default value -1, which indicates the property has not been set and that there is no request data to send).

  • When I send this request to the WebAPI application hosted on IIS 8.5, the POST request works normally.
  • Until recently, I was also able to send the request to the WebAPI running on IIS Express under the Visual Studio 2017 debugger, and again, it worked normally. Unfortunately I no longer know exactly which version of IIS Express was being used.

Recently I repaved my development machine with Windows 10 Version 1909 and reinstalled the latest Visual Studio 2017 15.9.22. Since doing this:

  • Requests sent from by development machine to the WebAPI hosted remotely on IIS 8.5 continue to work normally.
  • Requests sent to the WebAPI running locally on IIS Express 10.0.14358.1000 under the Visual Studio 2017 debugger are rejected with 411 LengthRequired.

I know that I can (and will eventually) fix this by modifying my client code to set ContentLength = 0.

But the client code is out in the field, and I'd like to fix this server-side if possible, e.g. by configuring IIS Express appropriately.

This looks to me like a breaking change in IIS behavior between IIS 8.5 and IIS Express 10.0.14358.1000, in that the latest IIS Express appears to be more restrictive in refusing to accept a POST without ContentLength header.

Is there a way of configuring IIS Express to behave as it used to? Or some other way of fixing this without modifying client code?


Solution

  • If you review the request, you will see that the response is not returned from IIS but http.sys HTTP-API/2.0.

    enter image description here

    Since there is no registry can fix this, I'm afraid the only way to fix 411 is modify you client code. Otherwise, IIS express can't even accept the request.

    https://support.microsoft.com/en-us/help/820129/http-sys-registry-settings-for-windows