Middleware, Run Vs Use, Custom middleware in ASP.NET Core
namespace ASPCoreMiddlewares
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
//app.MapGet("/", () => "Hello World!");
//app.Run() method is used to define middleware
//Run() method will not execute next subsequent middleware
//Below is custom middleware
//app.Run(async (context) =>
//{
// await context.Response.WriteAsync("Welcome to ASP.NET Core\n");
//});
//app.Use() method provides facility to call next middleware
app.Use(async (context, next) =>
{
await context.Response.WriteAsync("Welcome to ASP.NET Core\n");
await next(context);
});
app.Use(async (context,next) =>
{
await context.Response.WriteAsync("Programmentor\n");
await next(context);
});
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello Viewers...");
});
app.Run();
}
}
}
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
Comments
Post a Comment