<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        asp.net下cookies操作完美代碼

        來源:懂視網 責編:小采 時間:2020-11-27 22:43:27
        文檔

        asp.net下cookies操作完美代碼

        asp.net下cookies操作完美代碼: 代碼如下:using System; using System.Web; namespace Moosoft.OA.Public { /// <summary> /// Cookie幫助類 /// </summary> public class CookiesHelper { #region 獲取Cookie /// <
        推薦度:
        導讀asp.net下cookies操作完美代碼: 代碼如下:using System; using System.Web; namespace Moosoft.OA.Public { /// <summary> /// Cookie幫助類 /// </summary> public class CookiesHelper { #region 獲取Cookie /// <

        代碼如下:
        using System;
        using System.Web;
        namespace Moosoft.OA.Public
        {
        /// <summary>
        /// Cookie幫助類
        /// </summary>
        public class CookiesHelper
        {
        #region 獲取Cookie
        /// <summary>
        /// 獲得Cookie的值
        /// </summary>
        /// <param name="cookieName"></param>
        /// <returns></returns>
        public static string GetCookieValue(string cookieName)
        {
        return GetCookieValue(cookieName, null);
        }
        /// <summary>
        /// 獲得Cookie的值
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCookieValue(string cookieName, string key)
        {
        HttpRequest request = HttpContext.Current.Request;
        if (request != null)
        return GetCookieValue(request.Cookies[cookieName], key);
        return "";
        }
        /// <summary>
        /// 獲得Cookie的子鍵值
        /// </summary>
        /// <param name="cookie"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCookieValue(HttpCookie cookie, string key)
        {
        if (cookie != null)
        {
        if (!string.IsNullOrEmpty(key) && cookie.HasKeys)
        return cookie.Values[key];
        else
        return cookie.Value;
        }
        return "";
        }
        /// <summary>
        /// 獲得Cookie
        /// </summary>
        /// <param name="cookieName"></param>
        /// <returns></returns>
        public static HttpCookie GetCookie(string cookieName)
        {
        HttpRequest request = HttpContext.Current.Request;
        if (request != null)
        return request.Cookies[cookieName];
        return null;
        }
        #endregion
        #region 刪除Cookie
        /// <summary>
        /// 刪除Cookie
        /// </summary>
        /// <param name="cookieName"></param>
        public static void RemoveCookie(string cookieName)
        {
        RemoveCookie(cookieName, null);
        }
        /// <summary>
        /// 刪除Cookie的子鍵
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="key"></param>
        public static void RemoveCookie(string cookieName, string key)
        {
        HttpResponse response = HttpContext.Current.Response;
        if (response != null)
        {
        HttpCookie cookie = response.Cookies[cookieName];
        if (cookie != null)
        {
        if (!string.IsNullOrEmpty(key) && cookie.HasKeys)
        cookie.Values.Remove(key);
        else
        response.Cookies.Remove(cookieName);
        }
        }
        }
        #endregion
        #region 設置/修改Cookie
        /// <summary>
        /// 設置Cookie子鍵的值
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetCookie(string cookieName, string key, string value)
        {
        SetCookie(cookieName, key, value, null);
        }
        /// <summary>
        /// 設置Cookie值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetCookie(string key, string value)
        {
        SetCookie(key, null, value, null);
        }
        /// <summary>
        /// 設置Cookie值和過期時間
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expires"></param>
        public static void SetCookie(string key, string value, DateTime expires)
        {
        SetCookie(key, null, value, expires);
        }
        /// <summary>
        /// 設置Cookie過期時間
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="expires"></param>
        public static void SetCookie(string cookieName, DateTime expires)
        {
        SetCookie(cookieName, null, null, expires);
        }
        /// <summary>
        /// 設置Cookie
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expires"></param>
        public static void SetCookie(string cookieName, string key, string value, DateTime? expires)
        {
        HttpResponse response = HttpContext.Current.Response;
        if (response != null)
        {
        HttpCookie cookie = response.Cookies[cookieName];
        if (cookie != null)
        {
        if (!string.IsNullOrEmpty(key) && cookie.HasKeys)
        cookie.Values.Set(key, value);
        else
        if (!string.IsNullOrEmpty(value))
        cookie.Value = value;
        if (expires != null)
        cookie.Expires = expires.Value;
        response.SetCookie(cookie);
        }
        }
        }
        #endregion
        #region 添加Cookie
        /// <summary>
        /// 添加Cookie
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void AddCookie(string key, string value)
        {
        AddCookie(new HttpCookie(key, value));
        }
        /// <summary>
        /// 添加Cookie
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expires"></param>
        public static void AddCookie(string key, string value, DateTime expires)
        {
        HttpCookie cookie = new HttpCookie(key, value);
        cookie.Expires = expires;
        AddCookie(cookie);
        }
        /// <summary>
        /// 添加為Cookie.Values集合
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void AddCookie(string cookieName, string key, string value)
        {
        HttpCookie cookie = new HttpCookie(cookieName);
        cookie.Values.Add(key, value);
        AddCookie(cookie);
        }
        /// <summary>
        /// 添加為Cookie集合
        /// </summary>
        /// <param name="cookieName">Cookie名稱</param>
        /// <param name="expires">過期時間</param>
        public static void AddCookie(string cookieName, DateTime expires)
        {
        HttpCookie cookie = new HttpCookie(cookieName);
        cookie.Expires = expires;
        AddCookie(cookie);
        }
        /// <summary>
        /// 添加為Cookie.Values集合
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expires"></param>
        public static void AddCookie(string cookieName, string key, string value, DateTime expires)
        {
        HttpCookie cookie = new HttpCookie(cookieName);
        cookie.Expires = expires;
        cookie.Values.Add(key, value);
        AddCookie(cookie);
        }
        /// <summary>
        /// 添加Cookie
        /// </summary>
        /// <param name="cookie"></param>
        public static void AddCookie(HttpCookie cookie)
        {
        HttpResponse response = HttpContext.Current.Response;
        if (response != null)
        {
        //指定客戶端腳本是否可以訪問[默認為false]
        cookie.HttpOnly = true;
        //指定統一的Path,比便能通存通取
        cookie.Path = "/";
        //設置跨域,這樣在其它二級域名下就都可以訪問到了
        //cookie.Domain = "chinesecoo.com";
        response.AppendCookie(cookie);
        }
        }
        #endregion
        }
        }

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        asp.net下cookies操作完美代碼

        asp.net下cookies操作完美代碼: 代碼如下:using System; using System.Web; namespace Moosoft.OA.Public { /// <summary> /// Cookie幫助類 /// </summary> public class CookiesHelper { #region 獲取Cookie /// <
        推薦度:
        標簽: 操作 cookie 代碼
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 黄网址在线永久免费观看 | 欧洲人成在线免费| 久久亚洲色一区二区三区| 色九月亚洲综合网| 免费国产在线观看| 丁香六月婷婷精品免费观看| 国产成人精品久久亚洲| 国产男女爽爽爽免费视频| 亚洲av永久无码精品网站| 亚洲成人免费在线| 亚洲手机中文字幕| 女人18毛片水真多免费看| 在线亚洲高清揄拍自拍一品区| 免费鲁丝片一级观看| 国产产在线精品亚洲AAVV| 亚洲av中文无码| 久久国产免费观看精品| 亚洲白嫩在线观看| 青青青青青青久久久免费观看| 国产精品无码亚洲一区二区三区| 亚洲成a人片在线播放| 精品成人免费自拍视频| 亚洲人成电影在线观看网| 国产男女猛烈无遮挡免费视频网站| 日韩欧美亚洲国产精品字幕久久久| 亚洲AⅤ视频一区二区三区| 花蝴蝶免费视频在线观看高清版| 免费看黄网站在线看| 久久久精品国产亚洲成人满18免费网站| 国产综合免费精品久久久| 久久久久久久亚洲Av无码| 免费无码看av的网站| 热久久这里是精品6免费观看| 亚洲精品亚洲人成在线观看麻豆| 成人免费a级毛片无码网站入口| 人妻无码中文字幕免费视频蜜桃| 久久精品国产亚洲77777| 免费h成人黄漫画嘿咻破解版| 久久青草免费91线频观看不卡| 亚洲乱色伦图片区小说| 国产A在亚洲线播放|