You can create your own custom Middleware class. This can either be by implementing the IMiddleware
interface or just creating a class with a public method named Invoke
or InvokeAsync
. To add the middleware to your pipeline you can create a static method like so:
public static IApplicationBuilder UseCustomMiddleware(this IApplicationBuilder builder)
{
return builder.UseMiddleware<CustomMiddleware>();
}
then in Startup.cs
:
app.UseCustomMiddleware();
See this page for more information on middleware.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…