如何检查用户"登录"? [英] How to check user is "logged in"?
本文介绍了如何检查用户"登录"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用形式的验证下面的方法在我的ASP.NET应用程序
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?
推荐答案
我设法找到正确的。这是下文。
I managed to find the correct one. It is below.
bool val1 = System.Web.HttpContext.Current.User.Identity.IsAuthenticated
修改
此编辑要归功于@Gianpiero Caretti谁在评论认为这一点。
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
这篇关于如何检查用户"登录"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文