Login page with cookie valid

Salvatore Rizzo 21 Reputation points

I have a small aspnet core mvc .net 5 project with a simple authentication system.
At the login post action I create a cookie like this:

//Generate the user's cookie!
var authProperties = new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTimeOffset.Now.AddHours(12) };
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), authProperties);

Why, despite seeing the valid cookie in the browser, do I immediately get a redirect to the login page?


A set of technologies in the .NET Framework for building web applications and XML web services.
3,995 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 52,311 Reputation points

    The point of HttpContext.SignInAsync is to set a cookie and redirect to the url specified in properties. Usually a return url is passed to the login page, and the RedirectUri is set to this in the signin code. You appear to not be doing this, so it defaults to the current page.

    0 comments No comments

  2. Salvatore Rizzo 21 Reputation points

    Thanks for the reply but the problem is not the landing page after the post, but the redirect to the login that occurs after a few minutes of browsing the site.