有关登录控制的问题 [英] problem about login control

查看:89
本文介绍了有关登录控制的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用默认登录控件的网站,该控件在
无需注销即可跨站点

我想要
当我再次来到网站时,我已经登录

这是我的桌子

ID
电子邮件
密码
名称


我的登录control.cs

i have the website in which i am using the default login control i wnat that when
cross the site without logout

i want
when i come again to site i am already login

this my table

Id
Email
Password
Name


my login control.cs

protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void ctlLogin_Authenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        CheckBox chBox = (CheckBox)ctlLogin.FindControl("RememberMe");
        Authenticated = UserAuthenticate(ctlLogin.UserName, ctlLogin.Password);
        e.Authenticated = Authenticated;
       if (Authenticated == true)
        {
            if (chBox.Checked == true)
            {
                Response.Cookies["RFriend_Email"].Value = ctlLogin.UserName;
                Response.Cookies["RFriend_PWD"].Value = ctlLogin.Password;
                Response.Cookies["RFriend_UID"].Value = Session["Id"].ToString();
               Response.Cookies["RFriend_Email"].Expires = DateTime.Now.AddMonths(3);
                Response.Cookies["RFriend_PWD"].Expires = DateTime.Now.AddMonths(3);
               Response.Cookies["RFriend_UID"].Expires = DateTime.Now.AddMonths(3);
            }
            Response.Redirect("UserDetails.aspx?Id=" +Session["Id"].ToString());
           
       }
    }
    private bool UserAuthenticate(string UserName, string Password)
    {
        bool boolReturnValue = false;
        //--------------------------------
        //Check UserID From Config File
        
            //--------------------------------
            dt = new DataTable();
            SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\Project1\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
            string chkUser = "Select * FROM [User] where Email=''" + UserName + "'' AND Password=''" + Password + "''";
            dt = dbClass.ConnectDataBaseReturnDT(chkUser);
            if (dt.Rows.Count > 0)
            {
                boolReturnValue = true;
                Session["Id"] = dt.Rows[0]["Id"].ToString();
                string que = "UPDATE [User] SET LastLogin = GETDATE() where Id=" + Session["Id"].ToString();
               // DateTime registerdate = (DateTime)dt.Rows[0]["RegisterDate"];
                //string que1 = "UPDATE [User] SET RegisterDate = GETDATE() where Id=" + Session["UserId"].ToString();
                dbClass.ConnectDataBaseToInsert(que);
                //dbClass.ConnectDataBaseToInsert(que1);
            }
            return boolReturnValue;
        

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
}


在masterpage.cs中


in masterpage.cs

protected void Page_Load(object sender, EventArgs e)
   {
       if ((!object.Equals(Request.Cookies["RFriend_Email"], null)) && (!object.Equals(Request.Cookies["RFriend_PWD"], null)) && (!object.Equals(Request.Cookies["RFriend_UID"], null)))
       {
           if ((!object.Equals(Request.Cookies["RFriend_Email"].Value, "")) && (!object.Equals(Request.Cookies["RFriend_PWD"].Value, "")) && (!object.Equals(Request.Cookies["RFriend_UID"], "")))
           {
               Session["UserEmail"] = Request.Cookies["RFriend_Email"].Value;
               Session["Password"] = Request.Cookies["RFriend_PWD"].Value;
               Session["UserId"] = Request.Cookies["RFriend_UID"].Value;
           }

           else
           {
           }
       }
    }

推荐答案

注销时调用Session.LogoutSession.Abandon.


这篇关于有关登录控制的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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