zoukankan      html  css  js  c++  java
  • .net中如何使用cookie

    比如建立一个名为aspcn,值为灌水小鱼的cookie

    HttpCookie cookie = new HttpCookie["aspcn"];
    cookie.Value = "灌水小鱼";
    Response.AppendCookie(cookie);

    取出Cookie值也很简单

    HttpCookie cookie = Request.Cookies["aspcn"];
    cookieValue = cookie.Value;

    在一个Cookie中储存多个信息,那也没有问题。比如在名为aspcn的cookie下加多个信息

    HttpCookie cookie = new HttpCookie("aspcn");
    cookie.Values.Add("webmaster","灌水小鱼");
    cookie.Values.Add("writer","beige");
    cookie.Values.Add("LinkColor","blue");
    Response.AppendCookie(cookie);

    取出信息也一样简单

    HttpCookie cookie = Request.Cookies["aspcn"];
    value1 = cookies.Values["webmaster"];
    value2 = cookies.Values["writer"];
    
    HttpCookie cookie = Request.Cookies[strKey];
    if(null == cookie)
    {
    //cookie不存在
    } 

    先看看有没有写入客户端

    cookie=new HttpCookie("www.xx.org");
    cookie.Values.Add("UserType", ddlLoginType.SelectedItem.Value);
    cookie.Values.Add("UserName", tbUserName.Text.Trim());
    cookie.Values.Add("Password", tbPassword.Text.Trim());
    cookie.Values.Add("Access",i.ToString());
    Response.AppendCookie(cookie);
    //检查COOKIE是否已经写入浏览器
    cookie = Request.Cookies["www.xx.org"];
    if(cookie==null||cookie.ToString()=="")
    {
    //用session存储
    LoginUser loginUser = new LoginUser();
    loginUser.UserName = tbUserName.Text.Trim();
    loginUser.Password = tbPassword.Text.Trim();
    loginUser.UserType = ddlLoginType.SelectedItem.Value;
    loginUser.Access = i;
    Session["www.xx.org"] = loginUser;
    } 
  • 相关阅读:
    原码, 反码, 补码的基础概念和计算方法.
    QoS in RoCE
    TCP拥塞控制算法之NewReno和SACK
    intel xeon家族介绍
    Intel 处理器架构演进 转
    IP报文头详解
    高性能网络服务器编程:为什么linux下epoll是最好,Netty要比NIO.2好?
    tcp拥塞控制 tahoe reno new reno sack
    TCP/IP详解--拥塞控制 慢启动 快恢复 拥塞避免
    LTTng 简介&使用实战
  • 原文地址:https://www.cnblogs.com/longshiyVip/p/5003309.html
Copyright © 2011-2022 走看看