title: Set the login url in ASP.Net MVC Core 2.0
body: <p>Due to the fact that I am not good enough in authentication related stuff and I want to port a custom authentication to the ".Net Core 2.0" I need help. There are several similar questions out there but mine is a bit different. The user can easily log in and log out to the project and just need to set the login URL for the time when the user is not logged in and should redirect to the login page.</p>
  
  <p>I have already checked (<a href="https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?tabs=visual-studio%2Caspnetcore2x#tabpanel_yS0QDAFpXJ-1_aspnetcore2x" rel="nofollow noreferrer">this</a>, <a href="https://stackoverflow.com/questions/43961571/asp-net-core-2-0-preview-1-how-to-set-up-cookie-authentication-with-custom-logi#answer-45664413">this</a> or several other pages but they are mostly outdated - related to older versions - or they do not fit in my case)
  My Startup.cs:</p>
  
  <pre><code>// This method gets called by the runtime. Use this method to add services to the container.
      // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
      public void ConfigureServices(IServiceCollection services)
      {
          var builder = services.AddMvc(options =&gt; {
              options.ModelBinderProviders.Insert(0, new Olive.Mvc.OliveBinderProvider());
          })
          .AddJsonOptions(options =&gt;
          {
              options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
          })
          .ConfigureApplicationPartManager(manager =&gt;
          {
              var oldMetadataReferenceFeatureProvider = manager.FeatureProviders.First(f =&gt; f is MetadataReferenceFeatureProvider);
              manager.FeatureProviders.Remove(oldMetadataReferenceFeatureProvider);
              manager.FeatureProviders.Add(new ReferencesMetadataReferenceFeatureProvider());
          }); ;
  
          services.AddSingleton&lt;IUserStore&lt;User&gt;, UserStore&gt;();
          services.AddSingleton&lt;IRoleStore&lt;string&gt;, RoleStore&gt;();
          services.AddIdentity&lt;User, string&gt;();
          services.AddAuthentication(IdentityConstants.ApplicationScheme)
              .AddCookie(opt =&gt; opt.LoginPath = "/login");
  
          // Adds a default in-memory implementation of IDistributedCache.
          services.AddDistributedMemoryCache();
  
          services.AddSession();
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
              app.UseBrowserLink();
          }
          else
          {
              app.UseExceptionHandler("/Home/Error");
          }
  
          app.UseAuthentication();
  
          app.UseStaticFiles();
  
          app.UseSession();
  
          app.UseMvc(routes =&gt;
          {
              //routes.MapRoute(
              //    name: "default",
              //    template: "{controller=Home}/{action=Index}/{id?}");
          });
      }
  </code></pre>