亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

asp.net Cookie操作類

 更新時間:2009年12月15日 12:46:13   作者:  
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>
/// 保存一個Cookie
/// </summary>
/// <param name="CookieName">Cookie名稱</param>
/// <param name="CookieValue">Cookie值</param>
/// <param name="CookieTime">Cookie過期時間(小時),0為關(guān)閉頁面失效</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時間的話,關(guān)閉瀏覽器不會自動清除Cookie
//第二方法不設(shè)置Cookie時間的話,關(guān)閉瀏覽器會自動清除Cookie ,但是有效期
//多久還未得到證實。
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)文章

  • 一步步打造簡單的MVC電商網(wǎng)站BooksStore(3)

    一步步打造簡單的MVC電商網(wǎng)站BooksStore(3)

    這篇文章主要和大家一起一步步打造一個簡單的MVC電商網(wǎng)站,MVC電商網(wǎng)站BooksStore第三篇,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • ASP.NET下使用WScript.Shell執(zhí)行命令

    ASP.NET下使用WScript.Shell執(zhí)行命令

    ASP.NET下有自己的執(zhí)行CMD命令的方式,這里用WScript.Shell似有畫蛇添足之嫌,但是我們也不能排除真的有機器禁用了.NET的相關(guān)類,未雨綢繆嘛。當(dāng)然也不僅僅局限于WScript.Shell,只要是ASP中能用的組件,統(tǒng)統(tǒng)都可以用于ASP.NET中,而且還更方便!
    2008-05-05
  • php 三級聯(lián)動菜單

    php 三級聯(lián)動菜單

    這幾天用到了三級聯(lián)動,將asp的版本改為PHP的了
    2009-07-07
  • ASP.NET Core實現(xiàn)多文件上傳

    ASP.NET Core實現(xiàn)多文件上傳

    這篇文章介紹了ASP.NET Core實現(xiàn)多文件上傳的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • Asp.Net上傳圖片驗證代碼的小例子

    Asp.Net上傳圖片驗證代碼的小例子

    這篇文章介紹了Asp.Net上傳圖片驗證代碼的小例子,有需要的朋友可以參考一下
    2013-07-07
  • ASP.NET Core中實現(xiàn)全局異常攔截的完整步驟

    ASP.NET Core中實現(xiàn)全局異常攔截的完整步驟

    這篇文章主要給大家介紹了關(guān)于ASP.NET Core中如何實現(xiàn)全局異常攔截的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • ASP.NET?Core?MVC控制器請求依賴注入

    ASP.NET?Core?MVC控制器請求依賴注入

    這篇文章介紹了ASP.NET?Core?MVC控制器請求依賴注入的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • Asp.net中的頁面亂碼的問題

    Asp.net中的頁面亂碼的問題

    Asp.net中的頁面亂碼的問題...
    2006-09-09
  • 在ASP.NET Core中用HttpClient發(fā)送POST, PUT和DELETE請求

    在ASP.NET Core中用HttpClient發(fā)送POST, PUT和DELETE請求

    這篇文章主要介紹了在ASP.NET Core中用HttpClient發(fā)送POST, PUT和DELETE請求的方法,幫助大家更好的理解和學(xué)習(xí)使用ASP.NET Core,感興趣的朋友可以了解下
    2021-03-03
  • .net/c# memcached緩存獲取所有緩存鍵的方法步驟

    .net/c# memcached緩存獲取所有緩存鍵的方法步驟

    這篇文章主要介紹了.net/c# memcached緩存獲取所有緩存鍵的方法步驟,大家參考使用吧
    2013-12-12

最新評論