ModelBindingContext.HttpContext.Request.Body already consumed! #7251
Comments
Why should it happen in MVC? By default the http request body isn't rewindable. |
Because it's being used by mvc (not me) and I can't care to add a middleware for it? |
@ans-ashkan that means buffering the request body by default, which has performance implications. I think it should be opt-in (if we do it at all). You can easily write a filter to allow this for your specific action. It's rare that you read the body twice during a request. |
@davidfowl I agree, performance matters. the option to enable buffered request body can be useful though. |
Hi @ans-ashkan. What you're looking for can be achieved using Resource Filters, as they execute before Model Binding consumes the request body. You can get more details about Resource Filters at: https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters. As for baking this functionality into ASP.NET Core, we don't want to do that as we haven't heard much need of it, given the easy filters-based solution can be implemented. |
Request.Body is already consumed in CustomModelBinder or in an Action that contains some parameters.
Value of ms.Length always equals to 0.
the action with parameters code:
Also this always returns 0. but if you drop the paramter
string data
, it returns the actual body length.by using the following middleware, it works. but I consider this a workaround.
Shouldn't this happen internally (in mvc)?
(link to stack overflow question: https://stackoverflow.com/questions/48297331/using-request-body-in-custom-modelbinder)
(another related question on stack overflow: https://stackoverflow.com/questions/31389781/read-request-body-twice)
The text was updated successfully, but these errors were encountered: