title: ASP.Net core 3.1 website not redirecting when unauthorized
body: <p>I have an ASP.Net core 3.1 application with Identity and 2 pages: Index and Private (authorization required).
  When I browse to the Private page directly, I would expect the application to redirect me to the login page.
  Yet instead the broswer shows {&quot;message&quot;:&quot;Unauthorized&quot;}.
  Where is that message coming from and why is it not redirecting to login?</p>
  <p>(Navigating to login /Identity/Account/Login directly DOES show the login page)</p>
  <p>Startup.cs</p>
  <pre><code>public class Startup
  {
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
              options.UseSqlServer(
                  Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));
  
          services.AddDefaultIdentity&lt;BackendUser&gt;(options =&gt; options.SignIn.RequireConfirmedAccount = true)
              .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;();
  
  
          services.ConfigureApplicationCookie(options =&gt;
          {
              options.LoginPath = $&quot;/Identity/Account/Login&quot;;
              options.LogoutPath = $&quot;/Identity/Account/Logout&quot;;
          });
  
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          app.UseExceptionHandler(&quot;/Home/Error&quot;);
          app.UseHsts();
          app.UseStatusCodePages();
          app.UseHttpsRedirection();
          app.UseStaticFiles();
          app.UseRouting();
          app.UseAuthentication();
          app.UseAuthorization();
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapControllerRoute(
                  name: &quot;default&quot;,
                  pattern: &quot;{controller=Home}/{action=Index}/{id?}&quot;);
              endpoints.MapRazorPages();
          });
  
      }
  }
  </code></pre>
  <p>Controller</p>
  <pre><code>public class HomeController : Controller
  {
      public IActionResult Index()
      {
          return View();
      }
  
      [Authorize]
      public IActionResult Private()
      {
          return View();
      }
     
  }
  </code></pre>