1. 程式人生 > >asp.net Cookie 新增 刪除 獲取

asp.net Cookie 新增 刪除 獲取

logs ice crypt 用戶信息 asp.net bject pri 保存 trim

   //保存獲取 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 新增 刪除 獲取