一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

asp.net Cookie操作類

復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

namespace Jhgl.Smart
{
/// <summary>
/// Cookie操作類
/// </summary>
public class Cookie
{
/// <summary>
/// 保存一個(gè)Cookie
/// </summary>
/// <param name="CookieName">Cookie名稱</param>
/// <param name="CookieValue">Cookie值</param>
/// <param name="CookieTime">Cookie過(guò)期時(shí)間(小時(shí)),0為關(guān)閉頁(yè)面失效</param>
public static void SaveCookie(string CookieName, string CookieValue, double CookieTime)
{
HttpCookie myCookie = new HttpCookie(CookieName);
DateTime now = DateTime.Now;
myCookie.Value = CookieValue;

if (CookieTime != 0)
{
//有兩種方法,第一方法設(shè)置Cookie時(shí)間的話,關(guān)閉瀏覽器不會(huì)自動(dòng)清除Cookie
//第二方法不設(shè)置Cookie時(shí)間的話,關(guān)閉瀏覽器會(huì)自動(dòng)清除Cookie ,但是有效期
//多久還未得到證實(shí)。
myCookie.Expires = now.AddDays(CookieTime);
if (HttpContext.Current.Response.Cookies[CookieName] != null)
HttpContext.Current.Response.Cookies.Remove(CookieName);

HttpContext.Current.Response.Cookies.Add(myCookie);
}
else
{
if (HttpContext.Current.Response.Cookies[CookieName] != null)
HttpContext.Current.Response.Cookies.Remove(CookieName);

HttpContext.Current.Response.Cookies.Add(myCookie);
}
}
/// <summary>
/// 取得CookieValue
/// </summary>
/// <param name="CookieName">Cookie名稱</param>
/// <returns>Cookie的值</returns>
public static string GetCookie(string CookieName)
{
HttpCookie myCookie = new HttpCookie(CookieName);
myCookie = HttpContext.Current.Request.Cookies[CookieName];

if (myCookie != null)
return myCookie.Value;
else
return null;
}
/// <summary>
/// 清除CookieValue
/// </summary>
/// <param name="CookieName">Cookie名稱</param>
public static void ClearCookie(string CookieName)
{
HttpCookie myCookie = new HttpCookie(CookieName);
DateTime now = DateTime.Now;

myCookie.Expires = now.AddYears(-2);

HttpContext.Current.Response.Cookies.Add(myCookie);
}
}
}

AspNet技術(shù)asp.net Cookie操作類,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久精品成人免费网站 | 韩国一级毛片a级免观看 | 中文字幕日韩一区二区三区不 | 成人深夜视频 | 国产福利在线观看永久免费 | 国产美乳在线观看 | 在线观看免费视频网站色 | 影音先锋国产系列精品 | 国产亚洲精品一品区99热 | 福利视频一区青娱 | 91久久香蕉国产线看 | 国产色婷婷免费视频 | 亚洲国产精品久久 | 欧美性禁片在线观看 | 亚洲涩网 | 免费四虎永久在线精品 | 国产在线看不卡一区二区 | 天天久久狠狠伊人第一麻豆 | 久久久久久亚洲精品 | 国产h视频在线观看网站免费 | 狠狠干一区| 4hu四虎永久网址 | 国产精品精品国产 | 国产精品成人免费视频 | www.一区| 天天色天天射天天操 | 国产精彩刺激对白视频 | 视频在线国产 | 97在线视频精品 | 丝袜综合网 | 最新日本免费一区二区三区中文 | 一色屋成人免费精品网站 | xxx亚洲日本| 午夜影院在线免费观看 | 日韩一区二区视频在线观看 | 国产一区二区三区视频 | 男人女人的免费视频网站 | 色草视频 | 色吊丝欧美 | 国产福利小视频在线 | 久久精品国产91久久麻豆自制 |