首页 > 代码库 > asp.net Cookie 新增 删除 获取
asp.net Cookie 新增 删除 获取
//保存获取 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 新增 删除 获取
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。