• asp.net学习笔记·Cookie


    •        Cookie是和站点相关的,每次向服务器请求的时候,除了发送表单参数外,还会将和站点相关的Cookie值都提交给服务器,并且将服务器返回的Cookie更新到浏览器Cookie中去,且这是强制性的;
    •      Cookie的生命周期可以设置;
    •        缺点:Cookie不能存储过多的数据;
    •        网站优化案例:网站图片服务器和主站服务器域名不一样,降低提交Cookie消耗的流量;
    •        变量自增代码示例:
    • using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      
      public partial class 变量自增 : System.Web.UI.Page
      {
          private int a = 0;
          protected void Page_Load(object sender, EventArgs e)
          {
              if (IsPostBack)
              {
                  Response.SetCookie(new HttpCookie("num", "0"));
      //新建HttpCookie对象
                  this.Label1.Text = "0";
              }
          }
          protected void Button1_Click(object sender, EventArgs e)
          {
                int.TryParse(Request.Cookies["num"].Value, out a);
                  a++;
                  Response.SetCookie(new HttpCookie("num", a.ToString()));
                  this.Label1.Text = a.ToString();
             
          }
      }
      

        

  • 相关阅读:
    mall
    将UNICODE编码转换为中文
    460. LFU Cache
    957. Prison Cells After N Days
    455. Assign Cookies
    453. Minimum Moves to Equal Array Elements
    434. Number of Segments in a String
    1203. Sort Items by Groups Respecting Dependencies
    641. Design Circular Deque
    441. Arranging Coins
  • 原文地址:https://www.cnblogs.com/xuhongfei/p/2829387.html
Copyright © 2020-2023  润新知