title: Identity with ASP.Net Core 3.1 - on not authenticated, the app is not redirecting to Login in production like it does in dev
body: <p>I have an ASP.Net Core (3.1) web app that takes advantage of Identity.  It works as desired on my dev box, but does not redirect to login in production.</p>
  <p>Let me explain. I have a home/landing page with links to actions all over it.  If a user clicks on an action that requires Authentication (I am using the [Authorize] tag to specify that in my controller), then the app should redirect to the Login page to allow the user to login first and then redirect to the desired action that they click.  This works like magic almost completely out of the box with Identity <em>on my dev machine</em>.  When I push to production, this doesn't work like that.  It just sits on the home page with the URL changed to the action URL of the action clicked, which is OK I guess - at least it still enforces the Authentication - but I want the redirection.</p>
  <p>My production machine is a redhat linux server with apache and .netcore 3.1 setup on it.</p>
  <p>Here is my Startup:</p>
  <pre><code>public class Startup
  {
      //private readonly IConfiguration _configuration;
  
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddDistributedMemoryCache();
  
          services.AddControllersWithViews();
          services.AddRazorPages();
  
          services.AddDbContext&lt;AAPDbContext&gt;(options =&gt; {
              options.UseSqlServer(Configuration.GetConnectionString(&quot;AAP&quot;));
          });
          services.AddDbContext&lt;AuthDbContext&gt;(options =&gt; {
              options.UseSqlServer(Configuration.GetConnectionString(&quot;AAP&quot;));
          });
  
          services.AddTransient&lt;IEmailSender, EmailSender&gt;();
          services.Configure&lt;AuthMessageSenderOptions&gt;(Configuration);            
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler(&quot;/Home/Error&quot;);                
              app.UseHsts();
          }
          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>Here is my IdentityHostingStartup (added by Scaffolding and then tweaked):</p>
  <pre><code>public class IdentityHostingStartup : IHostingStartup
  {
      public void Configure(IWebHostBuilder builder)
      {
          builder.ConfigureServices((context, services) =&gt; {
              services.AddDbContext&lt;AuthDbContext&gt;(options =&gt;
                  options.UseSqlServer(
                      context.Configuration.GetConnectionString(&quot;AAP&quot;)));
  
              services.AddDefaultIdentity&lt;ApplicationUser&gt;(options =&gt; options.SignIn.RequireConfirmedAccount = true)
                  .AddRoles&lt;ApplicationRole&gt;()
                  .AddRoleManager&lt;RoleManager&lt;ApplicationRole&gt;&gt;()
                  .AddEntityFrameworkStores&lt;AuthDbContext&gt;();                
  
              services.ConfigureApplicationCookie(options =&gt;
              {
                  options.LoginPath = $&quot;/Identity/Account/Login&quot;;
                  options.LogoutPath = $&quot;/Identity/Account/Logout&quot;;
                  options.AccessDeniedPath = $&quot;/Identity/Account/AccessDenied&quot;;
              });
          });
      }
  }
  </code></pre>
  <p>I'm hoping this is a weird situation where some setting needs to be flipped on the linux box that is different b/c my dev box is a Win10 machine.</p>
  <p>Here is my config file for Apache:</p>
  <pre><code>&lt;VirtualHost *:*&gt;
      RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:80&gt;
      ServerName blah blah
      RewriteEngine on
  
      RewriteRule .* https://blahblahblah [R=302,QSA,L]
  &lt;/VirtualHost&gt;
  &lt;VirtualHost *:443&gt;
      ServerName blah blah
  
      ProxyPreserveHost On
      ProxyPass / http://127.0.0.1:5000/
      ProxyPassReverse / http://127.0.0.1:5000/
  
      SSLEngine on
      SSLCertificateFile /etc/pki/tls/certs/localhost.crt
      SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
      SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
  &lt;/VirtualHost&gt;
  </code></pre>