Skip to content
Sharp

ASP.NET Core basics · interview question

Put these ASP.NET Core middleware registrations in the recommended order in Program.cs.

OrderingMedium

Put the items in the correct order.

  1. app.UseHttpsRedirection()
  2. app.UseAuthentication()
  3. app.UseExceptionHandler("/error")
  4. app.MapControllers()
  5. app.UseAuthorization()
  6. app.UseRouting()

Answer and explanation

Correct answer

1. app.UseExceptionHandler("/error")
2. app.UseHttpsRedirection()
3. app.UseRouting()
4. app.UseAuthentication()
5. app.UseAuthorization()
6. app.MapControllers()

Why

Exception handling goes first so it can catch errors from everything after it. Routing must run before authentication/authorization so endpoint metadata (like [Authorize]) is known, and authentication must come before authorization. Endpoints are mapped last.

Test yourself on ASP.NET Core basics

A free test with instant, explained results. No account needed.

Start free test