最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net Cookie操作類

 更新時(shí)間:2009年12月15日 12:46:13   作者:  
Cookie操作類,本人得還很不錯(cuò)哦。
復(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);
}
}
}

相關(guān)文章

  • .net使用jwt進(jìn)行身份認(rèn)證的流程記錄

    .net使用jwt進(jìn)行身份認(rèn)證的流程記錄

    這篇文章主要給大家介紹了關(guān)于.net使用jwt進(jìn)行身份認(rèn)證的相關(guān)資料,JWT是Auth0提出的通過(guò)對(duì)JSON進(jìn)行加密簽名來(lái)實(shí)現(xiàn)授權(quán)驗(yàn)證的方案,本文通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-09-09
  • .NET?Core企業(yè)微信網(wǎng)頁(yè)授權(quán)登錄的實(shí)現(xiàn)

    .NET?Core企業(yè)微信網(wǎng)頁(yè)授權(quán)登錄的實(shí)現(xiàn)

    本文主要介紹了.NET?Core企業(yè)微信網(wǎng)頁(yè)授權(quán)登錄的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • ASP.NET?Core中MVC模式實(shí)現(xiàn)路由二

    ASP.NET?Core中MVC模式實(shí)現(xiàn)路由二

    這篇文章介紹了ASP.NET?Core中MVC模式實(shí)現(xiàn)路由的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • ASP.NET MVC中異常處理&自定義錯(cuò)誤頁(yè)詳析

    ASP.NET MVC中異常處理&自定義錯(cuò)誤頁(yè)詳析

    當(dāng)ASP.NET MVC程序出現(xiàn)了異常,怎么處理更加規(guī)范?下面這篇文章主要給大家介紹了關(guān)于ASP.NET MVC中異常處理&自定義錯(cuò)誤頁(yè)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • .Net Core官方JWT授權(quán)驗(yàn)證的全過(guò)程

    .Net Core官方JWT授權(quán)驗(yàn)證的全過(guò)程

    這篇文章主要給大家介紹了關(guān)于.Net Core官方JWT授權(quán)驗(yàn)證的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Asp.net中使用文本框的值動(dòng)態(tài)生成控件的方法

    Asp.net中使用文本框的值動(dòng)態(tài)生成控件的方法

    這篇文章主要介紹了Asp.net中使用文本框的值動(dòng)態(tài)生成控件的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-05-05
  • C#中的switch case使用介紹

    C#中的switch case使用介紹

    這篇文章主要介紹了C#中的switch case的使用,下面有個(gè)示例,大家可以參考下
    2014-06-06
  • asp.net 無(wú)刷新分頁(yè)實(shí)例代碼

    asp.net 無(wú)刷新分頁(yè)實(shí)例代碼

    asp.net 無(wú)刷新分頁(yè)實(shí)例代碼,需要的朋友可以參考一下
    2013-03-03
  • .net indexOf(String.indexOf 方法)

    .net indexOf(String.indexOf 方法)

    字符串的IndexOf()方法搜索在該字符串上是否出現(xiàn)了作為參數(shù)傳遞的字符串,如果找到字符串,則返回字符的起始位置 (0表示第一個(gè)字符,1表示第二個(gè)字符依此類推)如果說(shuō)沒(méi)有找到則返回 -1
    2012-10-10

最新評(píng)論

库伦旗| 罗源县| 乌拉特后旗| 嘉黎县| 西青区| 裕民县| 双城市| 宜春市| 昌宁县| 新竹市| 临汾市| 庆云县| 鄢陵县| 广德县| 库尔勒市| 兰考县| 丹凤县| 黄石市| 溆浦县| 新河县| 芒康县| 西乌珠穆沁旗| 浙江省| 贵南县| 平昌县| 城固县| 邵阳县| 澄城县| 永川市| 怀来县| 西青区| 开原市| 柯坪县| 凤城市| 固镇县| 忻州市| 九龙城区| 腾冲县| 陇川县| 凤山县| 慈溪市|