ASP.NET Core | Difference between app.Run and app.Use
1. app.Use method adds a middleware delegate to the application's request pipeline. When you want to pass the context to the next middleware then prefer app.Use method.
2. app.Run method adds a terminal middleware delegate to the application's request pipeline. When you want to terminate the pipeline then prefer to use the app.Run method.
app.Use((context, nextMidWare) => { context.Response.Body.Write("Hello app.Use"); nextMidWare(context);});
app.Run((context) => context.Response.Body.Write("Hello app.Run"));
app.Use((context, nextMidWare) => context.Response.Body.Write("Hello , again app.Use"));
Output:
Hello app.Use
Hello app.Run
Comments
Post a Comment