I am trying to read the body in a middleware for authentication purposes, but when the request gets to the api controller the object is empty as the body has already been re
This works with .Net Core 2.1 and higher.
Today I run in a similar issue. Long story short, what used to work with
Body.Seek(0, SeekOrigin.Begin);
resulted in today in exception, at least in my case. This happened after the code was migrated to the latest version of .NET Core.
The workaround for me was to add this:
app.Use(next => context => { context.Request.EnableBuffering(); return next(context);
Add this before setting up controllers or MVC. This seems to be added as part of the .NET Core 2.1 version.
Hope this helps someone!
Cheers and happy coding.