如何将用户设置为loggedIn状态 [英] how to set user in loggedIn state

查看:94
本文介绍了如何将用户设置为loggedIn状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建自定义登录页面..



其中我正在验证如下用户:



i have created custom login page..

in which i am validating a user like below :

if (Membership.ValidateUser(txt_email.Text, txt_password.Text))
             {
                 FormsAuthentication.RedirectFromLoginPage(txt_email.Text, cmb_remeber.Checked);

             }





工作正常。但我真正想要的是如果用户成功验证然后用户应该进入登录状态...并且loginStatus控件应该显示Logout。它正在验证成功,但loginstatus没有进入登录状态..



如何做到这一点???



It is working fine. but what i actually want is if user is validated succesfully then user should go in logged in state... And loginStatus control should show Logout. it is being validated successfully but loginstatus is not go in loggedIn state..

what to do to achieve this???

推荐答案

要检查用户是否已使用表格认证登录,请尝试 HttpContext.Current.User.Identity.IsAuthenticated

To check if a user is already logged in using forms authetication, try HttpContext.Current.User.Identity.IsAuthenticated.
if(HttpContext.Current.User.Identity.IsAuthenticated)
{
    //Do stuff
}


为什么不使用 LoginStatus [ ^ ]!br />
Why don't you use LoginStatus[^] !
Quote:

LoginStatus控件显示未经过身份验证的用户和注销链接的登录链接对于经过身份验证的用户。登录链接将用户带到登录页面。注销链接将当前用户的身份重置为匿名用户。

The LoginStatus control displays a login link for users who are not authenticated and a logout link for users who are authenticated. The login link takes the user to a login page. The logout link resets the current user's identity to be an anonymous user.





-KR



-KR


这篇关于如何将用户设置为loggedIn状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆