liveBook · Manning

IdentityResult

As explained in Pro ASP.NET Core 7, Tenth Edition

IdentityResult is an ASP.NET Core Identity result type that reports whether an identity operation succeeded and contains any resulting errors.

IdentityResult reports whether an ASP.NET Core Identity operation succeeded and exposes the errors produced when it failed. UserManager.CreateAsync returns it as Task<IdentityResult> after attempting to create an IdentityUser. section 38.3.3

Use the result to choose the request-processing path:

  • Check Succeeded; redirect to the user list when creation succeeds. section 38.3.3
  • Enumerate Errors when creation fails, and copy each IdentityError.Description into ModelState with ModelState.AddModelError. section 38.3.3
...
if (result.Succeeded) {
    return RedirectToPage("List");
}
foreach (IdentityError err in result.Errors) {
    ModelState.AddModelError("", err.Description);
}
...

The compact result-handling branch shows the practical success and failure paths. section 38.3.3

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines Succeeded and Errors, then demonstrates handling them; it stops short of describing result construction internals.
Examples
Uses user creation with Joe and Alice, showing successful creation, duplicate details, and password validation errors.
What it assumes
Assumes familiarity with IdentityUser, UserManager, model binding, and ModelState validation.
What you can do after
Apply it via UserManager.CreateAsync to redirect successful requests and surface IdentityError descriptions as validation messages.
How it connects
Connects UserManager, CreateAsync, IdentityUser, IdentityError, ModelState, and Razor Pages.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.