c# cookie帮助类
生活随笔
收集整理的這篇文章主要介紹了
c# cookie帮助类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;namespace Maticsoft.DBUtility
{public class CookieHelper{/// <summary>/// 設置cookie/// </summary>/// <param name="name"></param>/// <param name="value"></param>/// <param name="day"></param>/// <returns></returns>public static bool setCookie(string name, string value, int day){try{HttpCookie cookie = new HttpCookie(name);cookie.Expires = DateTime.Now.AddDays(day);cookie.Value = value;HttpContext.Current.Response.Cookies.Add(cookie);return true;}catch (Exception){return false;}}/// <summary>/// 獲取cookie/// </summary>/// <param name="name"></param>/// <returns></returns>public static string getCookie(string name){HttpCookie cookie = HttpContext.Current.Request.Cookies[name];if (cookie != null){return cookie.Value.ToString();}return null;}/// <summary>/// 刪除cookie/// </summary>/// <param name="name"></param>/// <returns></returns>public static bool delCookie(string name){try{HttpCookie cookie = new HttpCookie(name);cookie.Expires = DateTime.Now.AddDays(-1);HttpContext.Current.Response.Cookies.Add(cookie);return true;}catch (Exception){return false;}}}
}
轉載于:https://www.cnblogs.com/yang-2018/p/9996377.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的c# cookie帮助类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows nssm将应用程序做成服
- 下一篇: 源码分析系列1:HashMap源码分析(