【发布时间】:2018-06-20 01:33:53
【问题描述】:
我在Startup.Configure()方法中遇到了几种直接写简单中间件的方法:
// 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);
};
});
它们都一样吗?
【问题讨论】:
-
This 可能值得一看 1 vs 2
标签: c# asp.net-core .net-core middleware