zoukankan      html  css  js  c++  java
  • asp.net中读取、设置、移除Cookie

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Newtonsoft.Json;

    namespace Xys.PetShop.Web
    {
        public class Cookie<T>
        {
            public static void SetCookie(string name, T tValue, DateTime expires)
            {
                string value=JsonConvert.SerializeObject(tValue);
                HttpCookie cookie = new HttpCookie(name, value);
                cookie.Expires = expires;
                HttpContext.Current.Response.Cookies.Add(cookie);
            }

            public static T GetCookie(string name)
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
                if (cookie != null)
                {
                    return JsonConvert.DeserializeObject<T>(cookie.Value);
                }
                else
                    return default(T);
            }

            public static void RemoveCookie(string name)
            {
                HttpCookie cookie = new HttpCookie(name);
                cookie.Expires = DateTime.Now.AddDays(-1);
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
        }
    }

  • 相关阅读:
    Zookeeper 入门第一篇
    jmap命令
    Java中的原子操作类
    Fel表达式实践
    Fel表达式使用过程中需要注意的问题
    【luoguP1196】 [NOI2002]银河英雄传说--边带权并查集 ,
    【luoguP1955 】[NOI2015]程序自动分析--普通并查集
    【csp模拟赛2】 序列操作
    【csp模拟赛2】 爆搜 方格加数
    HZWER
  • 原文地址:https://www.cnblogs.com/50614090/p/2377234.html
Copyright © 2011-2022 走看看