This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16484|Reply: 0

[ASP.NET] asp.net implement cookies to save values

[Copy link]
Posted on 4/2/2015 10:29:29 AM | | |

Use Request to obtain the client cookie to determine whether it is empty

  if (Request.Cookies["UserInfo"] == null)
            {
                Create a cookie and name it
                HttpCookie cookietwo = new HttpCookie("UserInfo");
             //   cookietwo. Name = "UserInfo";
                Cookies are valid for one year
                cookietwo. Expires = DateTime.Today.AddDays(360);
                Set the corresponding key value for the cookie
                cookietwo. Values["username"] = txtUserName.Text;
                cookietwo. Values["pwd"] = txtPassword.Text;
              //  CookieHelp.CookieHelper.AddCookie(cookietwo);
                Add to the cookie with Response
                Response.Cookies.Add(cookietwo);
            }



Use Request to obtain the client cookie to determine whether it is empty

  if (Request.Cookies["UserInfo"] != null)
            {

Read the cookie key
                txtUserName.Text = Request.Cookies["UserInfo"]["username"]. ToString();
                txtPassword.Text = Request.Cookies["UserInfo"]["pwd"]. ToString();
            }




Previous:asp.net the principle and code of image captcha generation
Next:ASP.NET knowledge points
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com