ASP.NET Core Interview Question #127

What is authorization in ASP.NET Core?

Authentication, Authorization & Security Mid-Level Intermediate

Quick Interview Answer

Authorization determines whether an authenticated or anonymous user is allowed to perform an operation or access a resource. ASP.NET Core supports role-based, claims-based, policy-based, and resource-based authorization.

Detailed Explanation

Authorization determines whether an authenticated or anonymous user is allowed to perform an operation or access a resource. ASP.NET Core supports role-based, claims-based, policy-based, and resource-based authorization.

Authorization usually runs after authentication so policies can evaluate the current ClaimsPrincipal. The Authorize attribute or endpoint authorization metadata can require authenticated users or named policies.

Code Example

[Authorize]
public class AccountController : Controller
{
    public IActionResult Profile() => View();
}