liveBook · Manning

AddClaimAsync

As explained in ASP.NET Core in Action, 3e

AddClaimAsync is an ASP.NET Core Identity operation that asynchronously adds a claim to a user account.

AddClaimAsync asynchronously attaches a custom claim to an ASP.NET Core Identity user. A registration handler can store a FullName claim after creating the user, then continue with email confirmation or sign-in. section 23.6

A practical registration flow is:

  • Add a Name property to the registration input model and a matching field to the Razor view. section 23.6
  • Protect later claim-management pages so users cannot change sensitive data such as their own permissions. section 23.6

Displaying the claim

After sign-in, retrieve the claim through the ClaimsPrincipal, for example with User.FindFirstValue("FullName") in a Razor view.

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains the call within a simplified registration handler and defers boilerplate, extensive validation, and abstraction.
Examples
Uses a FullName claim added during registration and displayed with FindFirstValue in a Razor view.
What it assumes
Assumes an Identity registration flow with ApplicationUser, UserManager, Razor Pages, and sign-in already established.
What you can do after
Apply it via UserManager to attach custom claims and retrieve them through the signed-in ClaimsPrincipal.
How it connects
Connects ASP.NET Core Identity, UserManager, claims, ClaimsPrincipal, sign-in, and Razor Pages.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.