Skip to content

Instantly share code, notes, and snippets.

@shinkathe
Created May 29, 2018 13:39
Show Gist options
  • Save shinkathe/f82943d9f45315e172f79e3a81999b43 to your computer and use it in GitHub Desktop.
Save shinkathe/f82943d9f45315e172f79e3a81999b43 to your computer and use it in GitHub Desktop.
EnableRewind + StatusCodesPagesWithReExecute
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseStatusCodePagesWithReExecute("/StatusCode/{0}");
app.Use(async (context, next) =>
{
context.Request.EnableRewind();
using (var i = new StreamReader(context.Request.Body))
{
try
{
Debug.WriteLine(context.Request.Path);
context.Request.Body.Position = 0;
Debug.WriteLine($"Request body: {i.ReadToEnd()}");
}
catch (Exception e)
{
Debug.WriteLine(e);
throw;
}
}
await next.Invoke();
});
app.UseMvc();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment