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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With