I encountered several ways of writing simple middleware directly in Startup.Configure() method:
// Syntax 1.
app.Use((context, next) =>
{
context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
return next();
});
// Syntax 2.
app.Use(async (context, next) =>
{
context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
await next();
});
// Syntax 3.
app.Use(async (context, next) =>
{
context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
await next.Invoke();
});
// Syntax 4.
app.Use(next =>
{
return ctx =>
{
ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff");
return next(ctx);
};
});
Are they all the same?