Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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");
}

in masterpage.cs
C#
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
           {
           }
       }
    }
Posted
Updated 23-May-11 6:24am
v3

1 solution

Call Session.Logout or Session.Abandon when you logout.
 
Share this answer
 
Comments
[no name] 23-May-11 3:09am    
i do this but result is same

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900