title: Authorize(Roles = "Admin") always return ACCESS DENIED
body: <p>I'm spending lot time with this thing that appear easy, but can't find solution.</p>
  
  <p>Create a project and working well, login, register, etc. But Authorization not working with roles. Roles are created and setteds:</p>
  
  <p>But always return Access Denied when try to access:</p>
  
  <pre><code>public class _ConfigurationsController : Controller
  {
      [Authorize(Roles = "AdminApp")]
      public IActionResult Index()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>Startup.cs
  ...</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
      {
          // This lambda determines whether user consent for non-essential cookies is needed for a given request.
          options.CheckConsentNeeded = context =&gt; true;
          options.MinimumSameSitePolicy = SameSiteMode.None;
      });
  
      services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString("MyConnection")));
  
      services.AddDbContext&lt;Scaffolding_AutoGer_Context&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString("MyConnection")));
  
      services.AddDefaultIdentity&lt;IdentityUser&gt;()
          .AddRoles&lt;IdentityRole&gt;()
          .AddRoleManager&lt;RoleManager&lt;IdentityRole&gt;&gt;()
          .AddDefaultTokenProviders()
          .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;();
  
      services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
  
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  
  }
  
  
  public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
          app.UseDatabaseErrorPage();
      }
      else
      {
          app.UseExceptionHandler("/Home/Error");
          app.UseHsts();
      }
  
      app.UseHttpsRedirection();
      app.UseStaticFiles();
      app.UseCookiePolicy();
  
      app.UseAuthentication();
  
      app.UseMvc(routes =&gt;
      {
          routes.MapRoute(
              name: "default",
              template: "{controller=Home}/{action=Index}/{id?}");
      });
  }
  </code></pre>
  
  <p><strong>In debug windows are show this messages:</strong></p>
  
  <pre><code>...Authorization.DefaultAuthorizationService:Information: Authorization failed.
  ...: Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'.
  ...: Executing ForbidResult with authentication schemes ().
  ...Authentication.Cookies.CookieAuthenticationHandler:Information: AuthenticationScheme: Identity.Application was forbidden.
  </code></pre>
  
  <p><strong>AspNetRoles Table</strong></p>
  
  <p><a href="https://i.stack.imgur.com/lD6sq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lD6sq.jpg" alt="enter image description here"></a></p>
  
  <p><strong>AspNetUsers Table</strong></p>
  
  <p><a href="https://i.stack.imgur.com/jBH2l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jBH2l.png" alt="enter image description here"></a></p>
  
  <p><strong>AspNetUserRoles Table</strong></p>
  
  <p><a href="https://i.stack.imgur.com/8ePlG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8ePlG.png" alt="enter image description here"></a></p>
  
  <p>MVC - Scaffolding project
  Individual Accounts Login
  .NET Core 2.1
  VS 2017</p>
  
  <p>UPDATED:</p>
  
  <p>Login class - autogenerate</p>
  
  <p>[AllowAnonymous]
  public class LoginModel : PageModel
  {
      private readonly SignInManager _signInManager;
      private readonly ILogger _logger;</p>
  
  <pre><code>public LoginModel(SignInManager&lt;IdentityUser&gt; signInManager, ILogger&lt;LoginModel&gt; logger)
  {
      _signInManager = signInManager;
      _logger = logger;
  }
  
  [BindProperty]
  public InputModel Input { get; set; }
  
  public IList&lt;AuthenticationScheme&gt; ExternalLogins { get; set; }
  
  public string ReturnUrl { get; set; }
  
  [TempData]
  public string ErrorMessage { get; set; }
  
  public class InputModel
  {
      [Required]
      [EmailAddress]
      public string Email { get; set; }
  
      [Required]
      [DataType(DataType.Password)]
      public string Password { get; set; }
  
      [Display(Name = "Memorizar?")]
      public bool RememberMe { get; set; }
  }
  
  public async Task OnGetAsync(string returnUrl = null)
  {
      if (!string.IsNullOrEmpty(ErrorMessage))
      {
          ModelState.AddModelError(string.Empty, ErrorMessage);
      }
  
      returnUrl = returnUrl ?? Url.Content("~/");
  
      // Clear the existing external cookie to ensure a clean login process
      await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
  
      ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
  
      ReturnUrl = returnUrl;
  }
  
  public async Task&lt;IActionResult&gt; OnPostAsync(string returnUrl = null)
  {
      returnUrl = returnUrl ?? Url.Content("~/");
  
      if (ModelState.IsValid)
      {
          // This doesn't count login failures towards account lockout
          // To enable password failures to trigger account lockout, set lockoutOnFailure: true
          var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true);
          if (result.Succeeded)
          {
              _logger.LogInformation("Usuário logado .");
              return LocalRedirect(returnUrl);
          }
          if (result.RequiresTwoFactor)
          {
              return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
          }
          if (result.IsLockedOut)
          {
              _logger.LogWarning("Conta bloqueada!");
              return RedirectToPage("./Lockout");
          }
          else
          {
              ModelState.AddModelError(string.Empty, "Login inválido.");
              return Page();
          }
      }
  
      // If we got this far, something failed, redisplay form
      return Page();
  }
  </code></pre>
  
  <p>}</p>