This is the example for remember a user in a system when he login for a particular site
--------------------------------------------------------------------
User objUser = new User();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Retrieve data from cookie
//----------------------------------------
HttpCookie cookie = Request.Cookies["User"];
if(cookie!=null)
{
chkCookies.Checked = true;
objUser.User ID = cookie["ID"];
objUser.Password = cookie["Password"];
AdminLogin(objUser);
}
}
}
private void UserLogin(User objUsr)
{
Collection userDetails = BLCustomer.UserLogin(objUsr);
if (userDetails .Count > 0)
{
Session["User"] = objUsr.UserID;
if (chkCookies.Checked == true)
{
//Here cookie is create............................
HttpCookie ck = Request.Cookies["User"];
if (ck == null)
{
ck = new HttpCookie("User");
}
ck["ID"] = objUsr.UserID;
ck["Password"] = objUsr.Password;
ck.Expires = DateTime.Now.AddMonths(1);
Response.Cookies.Add(ck);
}
Response.Redirect("abc.aspx");
}
else
{
lblMsg.Text = "Login fail!";
}
}
No comments:
Post a Comment