Practice question from Minimal APIs Introduction

What is the correct order for middleware in this Minimal API? A. 1 → 2 → 3 B. 1 → 3 → 2 C. 2 → 1 → 3 D. 3 → 1 → 2 E. 2 → 3 → 1

var app = builder.Build();
// What order should these be in?
// 1. app.UseAuthentication();
// 2. app.MapGet("/secure", () => "data").RequireAuthorization();
// 3. app.UseAuthorization();

Answer

B

Explanation

The correct order is UseAuthentication() → UseAuthorization() → MapGet(). Authentication must run first to identify the user, then authorization to check permissions, and finally endpoint mapping.

More questions from ASP.NET with .NET 10