How to check user is "logged in"? How to check user is "logged in"? asp.net asp.net

How to check user is "logged in"?


I managed to find the correct one. It is below.

bool val1 = System.Web.HttpContext.Current.User.Identity.IsAuthenticated

EDIT

The credit of this edit goes to @Gianpiero Caretti who suggested this in comment.

bool val1 = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated


The simplest way:

if (Request.IsAuthenticated) ...


if (User.Identity.IsAuthenticated){    Page.Title = "Home page for " + User.Identity.Name;}else{    Page.Title = "Home page for guest user.";}