码迷,mamicode.com
首页 > Web开发 > 详细

asp.net Cookie 新增 删除 获取

时间:2017-08-02 15:37:37      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:ssi   获取   public   stat   信息   保存   asp   removes   add   

   //保存获取 Cookie
    public  class OperatorProvider
    {
        public static OperatorProvider Provider
        {
            get { return new OperatorProvider(); }
        }

        private string LoginUserKey = "LoginUser2017";
        private string LoginProvider = Configs.GetValue("LoginProvider");

        public OperatorModel GetCurrent()
        {
            OperatorModel operatorModel = new OperatorModel();
            if (LoginProvider == "Cookie")
            {
                operatorModel = DESEncrypt.Decrypt(WebHelper.GetCookie(LoginUserKey).ToString()).ToObject<OperatorModel>();//通过解密 Coookie 获取当前登录用户信息
            }
            else
            {
                //通过解密 Session获取登录用户信息
                operatorModel = DESEncrypt.Decrypt(WebHelper.GetSession(LoginUserKey).ToString()).ToObject<OperatorModel>();//通过解密 Coookie 获取当前登录用户信息

            }
            return operatorModel;
        }

        public void AddCurrent(OperatorModel operatorModel)
        {
            if (LoginProvider == "Cookie")
            {
                //写入Cookie 并加密
                WebHelper.WriteCookie(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson()), 60);
            }
            else
            {
                //写入Session 并加密 
                WebHelper.WriteSession(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson()));
            }

            //获取软件 ID 
            WebHelper.WriteCookie("Schedule_mac", MD5.md5(NetWork.GetMacByNetworkInterface().ToJson(), 32));
            WebHelper.WriteCookie("Schedule_licence", Licence.GetLicence());

        }

        public void RemoveCurrent()
        {
            if (LoginProvider == "Cookie")
            {
                WebHelper.RemoveCookie(LoginUserKey.Trim());
            }
            else
            {
                WebHelper.RemoveSession(LoginUserKey.Trim());

            }
        }
    }

  

asp.net Cookie 新增 删除 获取

标签:ssi   获取   public   stat   信息   保存   asp   removes   add   

原文地址:http://www.cnblogs.com/0819lsl/p/7274042.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!