I am creating a login and registration with identity in asp.net core c#, I configured all the files and the database, and double checked and saw that the user is in AspNetUsers so the connection between the database and the program is working. I put when user is authenticated, it redirects to the home page but it is staying on the Log-In Page.
public async Task OnGetAsync(string returnUrl = null)
{
if (User.Identity.IsAuthenticated) { Response.Redirect("Home"); }
if (!string.IsNullOrEmpty(ErrorMessage))
{
ModelState.AddModelError(string.Empty, ErrorMessage);
}
returnUrl = returnUrl ?? Url.Content("~/");
// Clear the existing external cookie to ensure a clean login process
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
ReturnUrl = returnUrl;
}
Try to modify the code as below.
if (User.Identity.IsAuthenticated) {
Response.Redirect("/Home/Index");
}
Test Result