title: AuthorizeView Roles doesn't recognize role even though the code does
body: <p>I'm trying to set up authorization with Blazor .net core 3.1 and the AuthorizeView Roles doesn't seem to recognize the role that is in the database. On the other hand, if I try to do it in code and I've set up a little message if it finds the role with the user, it finds the role and displays the ""User is a Valid User" message. I'm using this with AzureAd Microsoft authentication and AspNetCore identity package.</p>
  
  <p>Here's the index page code</p>
  
  <pre><code>@page "/"
  @using Microsoft.AspNetCore.Authorization;
  @using Microsoft.AspNetCore.Identity;
  @inject UserManager&lt;IdentityUser&gt; _UserManager
  @inject RoleManager&lt;IdentityRole&gt; _RoleManager
  @inject AuthenticationStateProvider AuthenticationStateProvider
  @attribute [Authorize]
  
  
  &lt;span&gt;@Message&lt;/span&gt;
  
  &lt;AuthorizeView Roles="Users"&gt;
      &lt;Authorized&gt;
          &lt;p&gt;Youre In!&lt;/p&gt;
      &lt;/Authorized&gt;
  &lt;/AuthorizeView&gt;
  
  @code
  {
      [CascadingParameter]
      private Task&lt;AuthenticationState&gt; authStateTask { get; set; }
  
      string USER_ROLE = "Users";
  
      string CurrentEmail;
      string Message;
  
      protected override async Task OnInitializedAsync()
      {
          var authState = await authStateTask;
          var CurrentEmail = authState.User.Identity.Name;
          if (CurrentEmail.Contains("@users.com") == true)
          {
              var user = await _UserManager.FindByNameAsync(CurrentEmail);
              if (user == null)
              {
                  var newUser = new IdentityUser { UserName = CurrentEmail, Email = CurrentEmail };
                  var createResult = await _UserManager.CreateAsync(newUser);
                  if (createResult.Succeeded)
                  {
                      var roleResult = await _UserManager.AddToRoleAsync(newUser, USER_ROLE);
                      if (roleResult.Succeeded)
                      {
                          Message = ("Good job");
                      }
                  }
              }
              else
              {
                  var RoleResult = await _UserManager.IsInRoleAsync(user, USER_ROLE);
                  if(RoleResult == true)
                  {
                      Message = "User is a Valid User";
                  }
                  else
                  {
                      Message = "User is invalid";
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Here are my services:</p>
  
  <pre><code>        public void ConfigureServices(IServiceCollection services)
          {
              services.AddDbContext&lt;AppDbContext&gt;(options =&gt; options.UseSqlite("DataSource=db.db"));
  
              services.AddDefaultIdentity&lt;IdentityUser&gt;()
                  .AddRoles&lt;IdentityRole&gt;()
                  .AddEntityFrameworkStores&lt;AppDbContext&gt;();
  
              services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                  .AddAzureAD(options =&gt; Configuration.Bind("AzureAd", options));
  
              services.AddControllersWithViews(options =&gt;
              {
                  var policy = new AuthorizationPolicyBuilder()
                      .RequireAuthenticatedUser()
                      .Build();
                  options.Filters.Add(new AuthorizeFilter(policy));
              });
  
              services.AddScoped&lt;AuthenticationStateProvider, ServerAuthenticationStateProvider&gt;();
              services.AddRazorPages();
              services.AddServerSideBlazor();
              services.AddSingleton&lt;WeatherForecastService&gt;();
          }
  
  </code></pre>