[Authorize]
noun
say it: “AW-ther-yze” /ˈɔːθəraɪz/
An ASP.NET Core attribute that only lets signed-in users, or users in a role, reach an action or controller.
What is [Authorize]?
[Authorize] (or .RequireAuthorization()) means an endpoint needs a signed-in user, optionally with a role or policy. [AllowAnonymous] opens it again.
[Authorize(Roles = "Admin")]
[HttpDelete("{id:int}")]
public IActionResult Delete(int id) => NoContent();
In a sentence
- “Authorize(Roles = "Admin") keeps the Delete action for admins only.”
Level: Journeyman · More ASP.NET Core terms at this level
Updated