Created
May 29, 2018 13:39
-
-
Save shinkathe/f82943d9f45315e172f79e3a81999b43 to your computer and use it in GitHub Desktop.
EnableRewind + StatusCodesPagesWithReExecute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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