Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check user is "logged in"?

I am using form authentication with below method in my ASP.NET application

FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true); 

How do I check whether user is logged in or not? And how can I get the user name of a logged in user?

like image 464
BlueBird Avatar asked May 22 '11 06:05

BlueBird


People also ask

How can I see users logged in Linux?

Linux Command To List Current Logged In Users. w command – Shows information about the users currently on the machine, and their processes. who command – Display information about users who are currently logged in.

How do I know my user in cmd?

In the box, type cmd and press Enter. The command prompt window will appear. Type whoami and press Enter. Your current user name will be displayed.


1 Answers

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 
like image 140
BlueBird Avatar answered Oct 03 '22 20:10

BlueBird