Remember me Cookie
-
Hi all... I have a login form (username and password), and I want to add a checkbox (remember me), how can I perform this cookie? Thanks alot
Nour Abdel-Salam... A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)
This article shows you how to implement the above functionality in ASP.NET. Step 1: Add a checkbox in the login page You can add a checkbox in the login page by dragging and dropping a checkbox from the toolbox when you are in page design mode, or you can create a checkbox programmatically in the code behind class. The following code shows you how to do this in the second way: private CheckBox _rememberMeCheckBox; //..... this._rememberMeCheckBox = new CheckBox(); this._rememberMeCheckBox.Text = "Remember me next time"); this._rememberMeCheckBox.Checked = true; this.Controls.Add(this._rememberMeCheckBox); //..... Setp 2: Creat a cookie when a subscriber login create a cookie in the Cliked event handler of the login button: private void _LoginButton_Click(object sender, System.Web.UI.ImageClickEventArgs e) { //.... //.... ApplicationUser user = ApplicationUser.RetrieveCurrentUserByLoginId(userId); if (user != null && user.Password == password) { Session["user"] = user; Response.Cookies.Remove("CookieFromXXX"); if (this._rememberMeCheckBox != null && this._rememberMeCheckBox.Checked) { HttpCookie cookie = new HttpCookie(string.Format("cookie_from_{0}", this._host)); cookie.Values.Add("userId", user.Id); cookie.Values.Add("pwd", user.Password); cookie.Expires = DateTime.Now.AddYears(1); Response.Cookies.Add(cookie); } } //.... //.... } Step 3: Override the OnInit method in the base page If there is a base page which is the parent page of all other pages in your website, you can override the the OnInit method in the base page like the following code: override protected void OnInit(EventArgs e) { //.... //.... if (!IsPostBack && Session["user"] == null) { if (Request.Cookies["CookieFromXXX"] != null) { HttpCookie cookie = Request.Cookies["CookieFromXXX"]; string userId = cookie.Values["userId"].ToString(); string pwd = cookie.Values["pwd"].ToString(); ApplicationUser user = ApplicationUser.RetrieveCurrentUserByLoginId(userId); if (user != null user.Password == pwd) { Session["user"] = user; } } } base.OnInit(e); } Or you can add the above logic in the O
-
This article shows you how to implement the above functionality in ASP.NET. Step 1: Add a checkbox in the login page You can add a checkbox in the login page by dragging and dropping a checkbox from the toolbox when you are in page design mode, or you can create a checkbox programmatically in the code behind class. The following code shows you how to do this in the second way: private CheckBox _rememberMeCheckBox; //..... this._rememberMeCheckBox = new CheckBox(); this._rememberMeCheckBox.Text = "Remember me next time"); this._rememberMeCheckBox.Checked = true; this.Controls.Add(this._rememberMeCheckBox); //..... Setp 2: Creat a cookie when a subscriber login create a cookie in the Cliked event handler of the login button: private void _LoginButton_Click(object sender, System.Web.UI.ImageClickEventArgs e) { //.... //.... ApplicationUser user = ApplicationUser.RetrieveCurrentUserByLoginId(userId); if (user != null && user.Password == password) { Session["user"] = user; Response.Cookies.Remove("CookieFromXXX"); if (this._rememberMeCheckBox != null && this._rememberMeCheckBox.Checked) { HttpCookie cookie = new HttpCookie(string.Format("cookie_from_{0}", this._host)); cookie.Values.Add("userId", user.Id); cookie.Values.Add("pwd", user.Password); cookie.Expires = DateTime.Now.AddYears(1); Response.Cookies.Add(cookie); } } //.... //.... } Step 3: Override the OnInit method in the base page If there is a base page which is the parent page of all other pages in your website, you can override the the OnInit method in the base page like the following code: override protected void OnInit(EventArgs e) { //.... //.... if (!IsPostBack && Session["user"] == null) { if (Request.Cookies["CookieFromXXX"] != null) { HttpCookie cookie = Request.Cookies["CookieFromXXX"]; string userId = cookie.Values["userId"].ToString(); string pwd = cookie.Values["pwd"].ToString(); ApplicationUser user = ApplicationUser.RetrieveCurrentUserByLoginId(userId); if (user != null user.Password == pwd) { Session["user"] = user; } } } base.OnInit(e); } Or you can add the above logic in the O
-
could you please write it using VB.NET Thanks alot
Nour Abdel-Salam... A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)
-
why don't you try converting it yourself, there are plenty of converters out there and the rest you cvould probably do yourself