If you use application/x-www-form-urlencoded or multipart/form-data , you can safely call context.Request.ReadFormAsync() several times when it returns the cached instance on subsequent calls.
If you use a different type of content, you will have to manually buffer the request and replace the request body with a rewindable stream, such as a MemoryStream . Here you can use the built-in middleware (you need to register it in your pipeline):
app.Use(next => async context => {
You can also use the BufferingHelper.EnableRewind() extension, which is part of the Microsoft.AspNet.Http package: it is based on a similar approach, but relies on a special thread that starts buffering data in memory and associates everything with a temporary file on disk when the threshold is reached :
app.Use(next => context => { context.Request.EnableRewind(); return next(context); });
FYI: In the future, vNext will add buffer middleware.
Pinpoint
source share