Cookie操作公共方法类
/// <summary>
/// Cookie操作
/// </summary>
public class Cookie {
private Cookie() { }
private static Cookie _instance = new Cookie();
public static Cookie _ {
get { return _instance; }
set { _instance = value; }
}
/// <summary>
/// 添加Cookie
/// </summary>
/// <param name="key">键名</param>
/// <param name="value">键值</param>
/// <param name="hour">保存时间(小时)</param>
public void SetCookie(string key, string value, string path, string domain, DateTime expires) {
HttpCookie hc = new HttpCookie(key);
hc.Path = path;
hc.Domain = domain;
hc.Value = HttpUtility.UrlEncode(value);
hc.Expires = expires;
HttpContext.Current.Response.Cookies.Add(hc);
}
/// <summary>
/// 添加Cookie
/// </summary>
/// <param name="key">键名</param>
/// <param name="value">键值</param>
/// <param name="hour">保存时间(小时)</param>
public void SetCookie(string key, string value, string path, string domain, int hour) {
SetCookie(key, value, path, domain, DateTime.Now.AddHours(hour));
}
/// <summary>
/// 添加Cookie
/// </summary>
补充:软件开发 , C# ,