title: ASP.NET Core Identity Role, Claim and User
body: <p>I am an ASP.NET Core beginner. I'm stuck in role, claim and user relationship.</p>
  
  <p>I have a user <strong>Ben</strong>, user belongs to <strong>Admin</strong> role. <strong>Admin</strong> role has claims <strong>view-page</strong> and <strong>edit-page</strong> in database.</p>
  
  <p>But I can't get claims and roles to be belonging to that user:</p>
  
  <p>(Please see comment in code)</p>
  
  <pre><code>var user = await _userManager.FindByNameAsync(applicationUser.UserName);
  if(user != null) {
      var userClaims = await _userManager.GetClaimsAsync(user); // empty, WHY ?
      var userRoles = await _userManager.GetRolesAsync(user); // ['admin']
      var adminRole = DbContext.Roles.FirstOrDefault(x =&gt; x.Name == "Admin");
      IList&lt;Claim&gt; adminClaims;
      if(adminRole != null)
      {
          adminClaims = await _roleManager.GetClaimsAsync(adminRole);
          // correct =&gt; ['view-page', 'edit-page']
      }
      }
  }
  </code></pre>
  
  <p>In my mind, I understand when a user is a member of a role, he inherit that role's claims.</p>
  
  <p>Default ASP.NET Identity have 5 tables:</p>
  
  <ul>
  <li>Users.</li>
  <li>Roles.</li>
  <li>UserRoles - A user can have many roles.</li>
  <li>RoleClaims - A role can have many claims.</li>
  <li>UserClaims - A user can have many claims.</li>
  </ul>
  
  <p>Do i think correct ? Why userManager.GetClaimsAsync(user) returns empty claims ?</p>
  
  <p>Any suggestion?</p>