Giải thích về Middleware trong ASP.NET Core?
Giải thích về Middleware trong ASP.NET Core?
Middleware là các thành phần trong pipeline xử lý request/ response; mỗi middleware có thể xử lý, chỉnh sửa và chuyển tiếp (next) cho middleware kế tiếp, hoặc ngắt mạch (short-circuit).
Request → [Exception] → [HTTPS] → [StaticFiles] → [Routing] → [Auth] → [Endpoint]
Response ← (chạy ngược lại theo thứ tự)
// Inline
app.Use(async (ctx, next) =>
{
var sw = Stopwatch.StartNew();
await next(ctx); // chuyển tiếp
ctx.Response.Headers["X-Elapsed"] = sw.ElapsedMilliseconds.ToString();
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.