title: Redirect to login with attribute Authorize using cookies authentication in ASP.NET 5
body: <p>I am testing the <em>[Authorize]</em> attribute, but I can't make a redirect to login page if the user has not logged yet (the Chrome inspector returns a 401).</p>
  
  <p>This is my code to make the login in my <strong>Controller</strong> (very simple).</p>
  
  <pre><code>if (model.UserName == "admin" &amp;&amp; model.Password == "test")
  {
      var claims = new[] { new Claim("name", model.UserName), new Claim(ClaimTypes.Role, "Admin") };
      var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
      await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));
      return RedirectToAction("Index", "Home");
  }
  </code></pre>
  
  <p>And this is my configuration in the <strong>Startup.cs</strong> for logins:</p>
  
  <pre><code>app.UseCookieAuthentication(options =&gt;
      {
          options.AutomaticAuthenticate = true;
          options.LoginPath = new PathString("/Account/Login");
      });
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks!!</p>