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.
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?
2 answers
Sort by: Most helpful
-
-
Salvatore Rizzo 21 Reputation points
2023-01-16T21:45:17.7233333+00:00 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.