zoukankan      html  css  js  c++  java
  • C# CookieHelper

    1.写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.Value = strValue;
    cookie.Expires = DateTime.Now.AddMinutes(expires);
    HttpContext.Current.Response.AppendCookie(cookie);
    }

    2. 读cookie值

    /// <summary>
    /// 读cookie值
    /// </summary>
    /// <param name="strName"></param>
    /// <returns></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 "";
    }

    3.删除cookie对象

    /// <summary>
    /// 删除cookie对象
    /// </summary>
    /// <param name="cookieName"></param>
    public static void RemoveCookie(string cookieName)
    {
    HttpCookie objCookie = new HttpCookie(cookieName);
    objCookie.Expires = DateTime.Now.AddYears(-1);
    HttpContext.Current.Response.Cookies.Add(objCookie);
    }

  • 相关阅读:
    maven插件安装与使用
    java面试题
    关于java的GC
    技术人员要树立自己的品牌
    为什么IT公司都应该鼓励开源
    你应该坚持写博客 即使没有读者
    计算机基础
    收藏 | 产品经理不可不知的 7 种技术思维
    我讨厌你公事公办的样子
    子序列问题【LIS、LCS、LCIS】
  • 原文地址:https://www.cnblogs.com/xiao-wo-niu/p/12882825.html
Copyright © 2011-2022 走看看