Tutorial by Examples

Define your class that will represent your custom error. public class ErrorDto { public int Code { get; set; } public string Message { get; set; } // other fields public override string ToString() { return JsonConvert.SerializeObject(this); } } Then put nex...
The idea is to use HttpContext.Response.OnStarting callback, as this is the last event that is fired before the headers are sent. Add the following to your middleware Invoke method. public async Task Invoke(HttpContext context) { context.Response.OnStarting((state) => { if ...
From documentation: The HttpContext.Items collection is the best location to store data that is only needed while processing a given request. Its contents are discarded after each request. It is best used as a means of communicating between components or middleware that operate at different poi...
Run Terminates chain. No other middleware method will run after this. Should be placed at the end of any pipeline. app.Run(async context => { await context.Response.WriteAsync("Hello from " + _environment); }); Use Performs action before and after next delegate. app.Use(...

Page 1 of 1