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:

```cs
@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?