public class HelloMiddleware
{
private RequestDelegate _next;
public HelloMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
await context.Response.WriteAsync("Hello world from HelloMiddleware!\n");
await _next.Invoke(context);
await context.Response.WriteAsync("\nHello world from HelloMiddleware!\n");
}
}
app.UseMiddleware<HelloMiddleware>();