How does User.Identity.IsAuthenticated works in ASP.Net MVC

ramco1917
 
on Jul 16, 2021 01:00 AM
464 Views

Hi

How the below code works

<authentication mode="Forms">
<forms loginUrl="~/Home/Login" timeout="30" />
</authentication>

Main Layout File

<!DOCTYPE html>
@{
    if (!User.Identity.IsAuthenticated)
    {
        Context.Response.Redirect(Url.Action("Login", "Home"));
    }
}

Thanks

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 16, 2021 12:59 AM
ramco1917 says:
if (!User.Identity.IsAuthenticated)
{
Context.Response.Redirect(Url.Action("Login", "Home"));
}
}

It will check if the user is Authenticated or not.

If not Authenticated then redirect to the Login Action of Home Controller.