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;
}
Replace below code:
Response.Redirect("Home");
New Code:
return new RedirectToPageResult("/Home/Index");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.