zoukankan      html  css  js  c++  java
  • cookie的创建和读取简化版

    创建:

    HttpCookie cookie = new HttpCookie("user");
    
    
    cookie.Values["stfId"] = CookieManager.Encrypt(staff.Id.ToString(),"ToCookie");
    cookie.Values["dept"] = CookieManager.Encrypt(staff.Dept.DepartName, "ToCookie");
    cookie.Values["name"] = CookieManager.Encrypt(staff.StfName, "ToCookie");
    
    cookie.Expires = DateTime.Now.AddDays(1);
    HttpContext.Current.Response.SetCookie(cookie);

    //读取

    public string GetCookie(string cookName,string key)
    {
    if (Request.Cookies[cookName] == null)
    {
    return "";
    }
    
    if (Request.Cookies[cookName].Values[key] != null)
    {
    return CookieManager.Decrypt(Request.Cookies[cookName].Values[key].ToString(), "ToCookie");
    }
    else
    {
    return "";
    }
    }

    javjavascript cookie设置

    function setcookie(name,days)[1]
    
    {
    
    var url = document.domain;
    
    var exp = new Date();
    
    exp.setTime(exp.getTime() + days*24*60*60*1000);
    
    document.cookie = name + "="+ escape(url) +";expires="+ exp.toGMTString();
    
    }
    
    cookie取得
    
    function getcookie(name)
    
    {
    
    var arr = document.cookie.match(new RegExp("[sS]*"+ name +"=([^;]*)"));
    
    alert(arr);
    
    if(arr != null)
    
    return unescape(arr[1]);
    
    return null;
    
    }
    经验在于积累----武二郎
  • 相关阅读:
    北方联动科技论坛上的回答
    Fire Net
    The shortest problem(hdu,多校
    Air Raid
    过山车
    Courses
    Network
    Common Subsequence
    The mook jong
    Distribution money
  • 原文地址:https://www.cnblogs.com/zhanghai/p/4461175.html
Copyright © 2011-2022 走看看