zoukankan      html  css  js  c++  java
  • Cookie帮助类

    /// <summary>
    /// Cookie帮助类
    /// </summary>
    public class CookieUtils
    {
    /// <summary>
    /// 写cookie值
    /// </summary>
    /// <param name="strName">名称</param>
    /// <param name="strValue">值</param>
    public static void WriteCookie(string strName, string strValue)
    {
    HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
    if (cookie == null)
    {
    cookie = new HttpCookie(strName);
    }
    cookie.Value = strValue;
    HttpContext.Current.Response.AppendCookie(cookie);
    }
    /// <summary>
    /// 写cookie值
    /// </summary>
    /// <param name="strName">名称</param>
    /// <param name="strValue">值</param>
    /// <param name="strValue">过期时间(分钟)</param>
    public static void WriteCookie(string strName, string strValue, int expires)
    {
    HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
    if (cookie == null)
    {
    cookie = new HttpCookie(strName);
    }
    cookie.Path = "/";
    cookie.Value = strValue;
    cookie.Expires = DateTime.Now.AddMinutes(expires);
    HttpContext.Current.Response.AppendCookie(cookie);
    }
    /// <summary>
    /// 读cookie值
    /// </summary>
    /// <param name="strName">名称</param>
    /// <returns>cookie值</returns>
    public static string GetCookie(string strName)
    {
    if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
    {
    return HttpContext.Current.Request.Cookies[strName].Value.ToString();
    }
    return "";
    }
    /// <summary>
    /// 删除Cookie对象
    /// </summary>
    /// <param name="CookiesName">Cookie对象名称</param>
    public static void DelCookie(string CookiesName)
    {
    HttpCookie objCookie = new HttpCookie(CookiesName.Trim());
    objCookie.Expires = DateTime.Now.AddYears(-5);
    HttpContext.Current.Response.Cookies.Add(objCookie);
    }
    }

  • 相关阅读:
    利用guava来实现本地的cache缓存
    加减乘除工具类BigDecimalUtil
    linux使用apache发布静态html网页
    为什么从pycharm中打开的html文件会显示404?
    unittest测试框架生成可视化测试报告-BeautifulReport
    python虚拟环境迁移
    linux查看系统版本
    Webhook到底是个啥?
    钩子函数和回调函数的区别
    LookupError: "gw_lt" is not among the defined enum values
  • 原文地址:https://www.cnblogs.com/guzhengtao/p/20180706_1554.html
Copyright © 2011-2022 走看看