Read JSON post data in ASP.Net Core MVC Read JSON post data in ASP.Net Core MVC json json

Read JSON post data in ASP.Net Core MVC


By the time it gets to your middleware the request stream has already been read, so what you can do here is Microsoft.AspNetCore.Http.Internal.EnableRewind on the Request and read it yourself

Site wide :

Startup.csusing Microsoft.AspNetCore.Http.Internal;Startup.Configure(...){...//Its important the rewind us added before UseMvcapp.Use(next => context => { context.Request.EnableRewind(); return next(context); });app.UseMvc()...}

OR selective :

private async Task GenerateToken(HttpContext context)    {     context.Request.EnableRewind();     string jsonData = new StreamReader(context.Request.Body).ReadToEnd();    ...    }