Issue
I want to avoid users getting into the login page if already authenticated.
I know that you can use the RedirectToPage("/index")
but i don`t know were.
I've tried this:
@page
@model xxxxx.Accounts.LoginModel
@{
Layout = "EmptyLayout";
if (User.Identity.IsAuthenticated)
RedirectToPage("/index")
}
<!doctype html>
<html lang="es">
//login page
This don't work for me and I know that if (User.Identity.IsAuthenticated)
is true, and in the PageModel the Redirect("")
method works properly.
Is there any PageModel method like OnCreate(), OnLoad(),... to run code before the page is loaded? How can I achive this?
Solution
I belive that i was not on debug mode so i didn't get the breakpoint on the OnGet()
. So the solution is just to do this:
public async Task<IActionResult> OnGet()
{
if (User.Identity.IsAuthenticated)
return Redirect("/Index");
else return Page();
}
Answered By - F3rkun Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.