• cookie小记



                    清除cookie可用下面2种的方法。注意如果要清除的cookie的域是指定的,则这里也应该指定,否则无效
                    1:
                    Response.Cookies["mycookiename"].Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies["mycookiename"].Domain = ".test.com";


                    2:              
                    HttpCookie cookies = new HttpCookie("mycookiename", null);
                    cookies.Domain = ".test.com";
                    cookies.Expires = new DateTime(1900, 1, 1);
                    Response.Cookies.Add(cookies);

                  

                    3:

                    HttpCookie us = Request.Cookies["user"];
                    if (us != null)
                    {
                    //会让指定有效期的cookie变成会话cookie,要等关闭浏览器该cookie才消失
                    us.Values.Remove("username");
                    Response.AppendCookie(us);
                    }

                    4、

                   HttpCookie cookie = new HttpCookie("mycookiename2", cookievalue);
                   cookie.HttpOnly = true; //设置后客户端能看到,js无法访问到,js也无法修改名为mycookiename的值
                   cookie.Domain = ".test.com";
                   Response.Cookies.Add(cookie);

  • 相关阅读:
    java 连接SQL Server
    JAVA泛型
    JAVA 数组遍历
    JAVA注释
    Python正则表达式
    python练习题二
    Python函数
    Python练习题一
    重学python-列表的一些操作
    重学python-python-pandas库
  • 原文地址:https://www.cnblogs.com/tyhj-zxp/p/5556457.html
Copyright © 2020-2023  润新知