I want to redirect from my controller to a razor page that's in an area section. My controller user is restricted if the user is null then redirects to the login page in Area/Identity/Pages/Account/login.cshtml
.
My Controller:
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
//return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
return RedirectToPage("Login");
}
How do I write a return line to redirect to my login page using asp.net core 2.1
.
Use this line to redirect to page from controller action
return LocalRedirect("/Identity/Account/Login");
This works too:
return RedirectToPage("/Account/Login", new { area = "Identity" });
tested in asp.net core 2.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With