zoukankan      html  css  js  c++  java
  • Cookie基本使用

    1 通过HTTPCookies类进行创建

    创建Cookies:

    HttpCookie StudentCookies = new HttpCookie("StudentCookies");
    StudentCookies.Value = TextBox1.Text;
    StudentCookies.Expires = DateTime.Now.AddHours(1);
    Response.Cookies.Add(StudentCookies);

    读取Cookies:

    string roll = Request.Cookies["StudentCookies"].Value;

    2直接通过Response进行创建

    创建Cookies:

    Response.Cookies["StudentCookies"].Value = TextBox1.Text;
    Response.Cookies["StudentCookies"].Expires = DateTime.Now.AddDays(1);

    读取Cookies:

    string roll = Request.Cookies["StudentCookies"].Value;

    3多值的存储

    创建Cookies:

     
    Response.Cookies["StudentCookies"]["RollNumber"] = TextBox1.Text;
    Response.Cookies["StudentCookies"]["FirstName"] = "Abhimanyu";
    Response.Cookies["StudentCookies"]["MiddleName"] = "Kumar";
    Response.Cookies["StudentCookies"]["LastName"] = "Vatsa";
    Response.Cookies["StudentCookies"]["TotalMarks"] = "499";
    Response.Cookies["StudentCookies"].Expires = DateTime.Now.AddDays(1); 
     

    读取Cookies:

     
    string roll;
    roll = Request.Cookies["StudentCookies"]["RollNumber"];
    roll = roll + " " + Request.Cookies["StudentCookies"]["FirstName"];
    roll = roll + " " + Request.Cookies["StudentCookies"]["MiddleName"];
    roll = roll + " " + Request.Cookies["StudentCookies"]["LastName"];
    roll = roll + " " + Request.Cookies["StudentCookies"]["TotalMarks"];
    Label1.Text = roll; 

    4.删除Cookies的方法

    删除Cookies的实质是修改它的过期时间,代码如下:

    if (Request.Cookies["StudentCookies"] != null)
    {
        Response.Cookies["StudentCookies"].Expires = DateTime.Now.AddDays(-1);
        Response.Redirect("Result.aspx");  //to refresh the page
    }
  • 相关阅读:
    Flink实战(七十三):FLINK-SQL使用基础(一)简介(一)入门
    Flink实战(七十二):监控(四)自定义metrics相关指标(二)
    k8s启动
    k8s containerd
    安装containerd
    k8s镜像
    crictl
    Kubernetes: Using containerd 1.1 without Docker
    docker images --digests
    ctr images pull docker.io/library/redis:latest
  • 原文地址:https://www.cnblogs.com/xyangs/p/2466760.html
Copyright © 2011-2022 走看看