zoukankan      html  css  js  c++  java
  • 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;
                }
            }
        }
    }
    

      

  • 相关阅读:
    二叉搜索树的后序遍历序列
    验证二叉搜索树
    合并二叉树
    工龄计算方案
    hadoop集群中动态添加节点
    java知识点
    Hadoop经典案例(排序&Join&topk&小文件合并)
    mysql学习
    大数据开发面试
    我保存的网址
  • 原文地址:https://www.cnblogs.com/yang-2018/p/9996377.html
Copyright © 2011-2022 走看看