title: ASP.Net core MVC6 Redirect to Login when not authorised
body: <p>I am using ASP.Net core MVC 6, I am trying to get the user redirected to the login page if they are not authenticated.</p>
  
  <p>I cant seem to get it to work, currently the user just gets a blank page.</p>
  
  <p>Below is my ConfigureServices method in Startup.cs</p>
  
  <pre><code>        public void ConfigureServices(IServiceCollection services) {
          // Add framework services.
          services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
              options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
          );
  
          services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;(options =&gt; {
              // configure identity options
              options.Password.RequireDigit = true;
              options.Password.RequireLowercase = true;
              options.Password.RequireUppercase = true;
              options.Password.RequireNonAlphanumeric = true;
              options.Password.RequiredLength = 7;
  
              options.Cookies.ApplicationCookie.AutomaticAuthenticate = true;
              options.Cookies.ApplicationCookie.AutomaticChallenge = true;
              options.Cookies.ApplicationCookie.LoginPath = "/Account/Login";
  
              // User settings
              options.User.RequireUniqueEmail = true;
          })
              .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
              .AddDefaultTokenProviders();
  
          services.AddMvc();
  
          // Add application services.
          services.AddTransient&lt;IEmailSender, AuthMessageSender&gt;();
          services.AddTransient&lt;ISmsSender, AuthMessageSender&gt;();
      }
  </code></pre>