Post exception after 2.1 update

Topics: ASP.NET Web API
Jan 24, 2014 at 3:01 PM
I'm getting this exception during Posts to my WebApi methods after updating to 2.1. Everything worked fine with 2.0 and Gets work fine still. Any clues on where to look or fix this?

This method or property is not supported after HttpRequest.Form, Files, InputStream, or BinaryRead has been invoked. at System.Web.HttpRequest.GetInputStream(Boolean persistEntityBody, Boolean disableMaxRequestLength) at System.Web.HttpRequestWrapper.GetBufferlessInputStream() at System.Web.Http.WebHost.HttpControllerHandler.<>c__DisplayClass11.<ConvertRequest>b__c() at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.get_StreamContent() at System.Web.Http.WebHost.HttpControllerHandler.LazyStreamContent.CreateContentReadStreamAsync() at System.Net.Http.HttpContent.ReadAsStreamAsync() at System.Net.Http.HttpContentMultipartExtensions.<ReadAsMultipartAsync>d__0`1.MoveNext()
Jan 24, 2014 at 3:15 PM

We have encountered this kind of issue before and tried to fix it. From what I recall the request stream was being read in certain components before Web API tries to read it later during deserialization or in situation like yours.

Would it be possible for you to share a simple repro?



Jan 24, 2014 at 3:23 PM
Also what is the version of IIS that you are using?

Not sure if this matters but could you also check if you are using .NET 4.5 or 4.5.1 by checking the "Release" flag value of the following Registry entry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full

(for more details on can go to:
Jan 24, 2014 at 3:36 PM
I'm on windows 8.1, so .net 4.5.1 and IIS 8.5. The release flag is 378675.

Is it true that WebApi 2.1 only supports IIS 7.5 and up?
Jan 24, 2014 at 3:39 PM

Thanks for the details. I too have an exact configuration like yours and tried a simple scenario of Post and it works fine. So would it be possible for your to share a simple repro so that we can dig deeper into it?

Regarding Web API only supporting 7.5 and up: this was actually a regression in Web API 2.1 and are working towards fixing it. Following is the issue keeping track of it.

Jan 24, 2014 at 4:27 PM
Ok, I think I found the code that is causing the issue. In my global.asax Application_beginRequest method I have:

public void Application_BeginRequest(object sender, EventArgs e)
        var context = new HttpContextWrapper(this.Context);
        if (context.Request.IsAjaxRequest())
            this.Context.Response.SuppressFormsAuthenticationRedirect = true;
Taking that out in my sample makes my Post method work, having it in there breaks it. But this used to work with WebApi 2.0
Jan 24, 2014 at 4:31 PM

Great…thanks! for finding out the root cause…I will bring this up to the team and will keep you posted…

Jan 24, 2014 at 4:45 PM
I have now tried with my simple repro and the above piece of code, but i am unable to repro the issue...can you share a simple repro...
Jan 24, 2014 at 4:56 PM
This is the simplest way to get it to you: WebSite
Jan 30, 2014 at 2:36 AM
I've also had this post to web api issue since upgrading to the 5.1 stack. Nothing else I read here worked so I was forced to manually downgrade back to 5.0 and it all started working again.
Jan 30, 2014 at 7:08 AM
Exactly the same problem for me as well Daniel and I have had to roll back to 5.0. I will wait for any news on this thread (or others) before trying again.
Jan 30, 2014 at 4:17 PM
We are actively working to fix both these issues and release a patch soon. Will keep you posted once we have something to try out.
Jan 30, 2014 at 4:23 PM
Jan 30, 2014 at 8:20 PM
I too have just come across this problem after upgrading to 2.1. However after seeing the above issue is resolved I upgraded to the nightly builds from Jan 29 and the problem has gone away.
Feb 3, 2014 at 2:48 AM
Edited Feb 3, 2014 at 2:48 AM
This exception condition also is reproduced/raised when using Windows Identity Framework's WSFederationAuthenticationModule.

I see it has been fixed in the nightlys, any update on when a fixed build will be officially released via NuGet? Like others, we also had to roll back to 5.0...
Feb 3, 2014 at 5:06 PM
Hey @digitaldilemma,

We currently have what we consider Escrow bits in the nightly build. Did you try it and verified it works for your scenario?

In general we are trying to verify that there are no other breaking changes in these bits, but barring anything surprising we might find, these are the final bits at this point.

Looking forward for your feedback.
Feb 4, 2014 at 3:56 AM
I was also experiencing a problem with this issue. I upgrade the packages one by one and the problem starts occurring after installing this package:

If it helps, I have elmah, mini profiler, and glimpse installed and configured and when I disabled the Glimpse module in my web.config everything started working again.
Feb 7, 2014 at 9:24 PM
Edited Feb 7, 2014 at 9:26 PM
I am also having this issue. This should not be considered a feature; it is a bug. I see no reason why one should not be able to read the input stream multiple times. My specific problem occurs when I read the input stream as part of a client certificate authorization process tied to a custom attribute. Once the attribute is finished, the controller action simply blows chunks. I have reverted back to the 5.0 WebApi and all is working again.
Feb 10, 2014 at 6:34 PM
This issue has now been fixed. Please update your packages to the latest versions (5.1.1) to get the fix.

Daniel Roth
Feb 11, 2014 at 10:59 PM
I'm having an issue which is somewhat related to this I think.

I am reading the body stream from an owin middleware component, but WebApi fails miserably when doing this. Even when replacing the request body with a memory stream and/or resetting it.

I've created an issue for this:
Feb 12, 2014 at 12:06 AM

I was able to repro your issue. Can you try the following workaround (instead of the code that you showed in the bug description) when using 5.1.1 and see if this fixes your issue:

HttpContextBase contextBase = (HttpContextBase)context.Environment["System.Web.HttpContextBase"];
Stream buffreredRequestStream = contextBase.Request.InputStream;
// other code
buffreredRequestStream.Position = 0;
Request.Body = buffreredRequestStream;
Feb 12, 2014 at 12:17 AM
Edited Feb 12, 2014 at 12:19 AM

That works.

Although this creates a dependency on "System.Web.HttpContextBase", I can live with this for now.

edit: let's move the discussion to the workitem.