Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Remember me Cookie

Remember me Cookie

Scheduled Pinned Locked Moved ASP.NET
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nour123
    wrote on last edited by
    #1

    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)

    S 1 Reply Last reply
    0
    • N nour123

      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)

      S Offline
      S Offline
      sumit7034
      wrote on last edited by
      #2

      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

      N 1 Reply Last reply
      0
      • S sumit7034

        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

        N Offline
        N Offline
        nour123
        wrote on last edited by
        #3

        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)

        E 1 Reply Last reply
        0
        • N nour123

          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)

          E Offline
          E Offline
          eyeseetee
          wrote on last edited by
          #4

          why don't you try converting it yourself, there are plenty of converters out there and the rest you cvould probably do yourself

          N 1 Reply Last reply
          0
          • E eyeseetee

            why don't you try converting it yourself, there are plenty of converters out there and the rest you cvould probably do yourself

            N Offline
            N Offline
            nour123
            wrote on last edited by
            #5

            I did it thanks alot regards

            Nour Abdel-Salam... A Trainer and a Web Developer in Jedda Int'l Computer Center(JICC)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups