• 曾经用过的Cookie


      用户登陆记录一般用cookie或session,这里采用的是cookie比较安全,虽然的可能占用服务器的内存。

    public T_SysUser CurrentUser
            {
                get
                {
                    HttpCookieCollection cs = System.Web.HttpContext.Current.Request.Cookies;
                    HttpCookie id = cs["Ma_ID"];
                    HttpCookie username = cs["Ma_UserName"];
                    HttpCookie userpwd = cs["Ma_UserPwd"];
                    HttpCookie usergroup = cs["Ma_UserGroup"];
                    if (id != null && username != null && userpwd != null && usergroup != null)
                    {
                        return new T_SysUser
                        {
                            ID = int.Parse(id.Value),
                            UserName = HttpUtility.UrlDecode(username.Value),
                            UserPwd = userpwd.Value,
                            Group = int.Parse(usergroup.Value)
                        };
                    }
                    else
                    {
                        throw new Exception("登录超时,请退出系统重新登录");
                    }
                }
                set
                {                
                    HttpCookie id = new HttpCookie("Ma_ID", value.ID.ToString()) { Expires = DateTime.Now.AddDays(30) };
                    HttpCookie username = new HttpCookie("Ma_UserName", HttpUtility.UrlEncode(value.UserName).ToString()) { Expires = DateTime.Now.AddDays(30) };
                    HttpCookie userpwd = new HttpCookie("Ma_UserPwd", value.UserPwd.ToString()) { Expires = DateTime.Now.AddDays(30) };
                    HttpCookie usergroup = new HttpCookie("Ma_UserGroup", value.Group.ToString() == null ? "" : value.Group.ToString()) { Expires = DateTime.Now.AddDays(30) };
    
    
                    System.Web.HttpContext.Current.Response.SetCookie(id);
                    System.Web.HttpContext.Current.Response.SetCookie(username);
                    System.Web.HttpContext.Current.Response.SetCookie(userpwd);
                    System.Web.HttpContext.Current.Response.SetCookie(usergroup);
                }
            }

     

  • 相关阅读:
    使用vue自定义组件以及动态时间
    vue案列
    解决adb devices无法连接夜神模拟器
    手动解除浏览器跨域限制
    HBuilder实现WiFi调试Android
    Spring mvc文件下载
    3大框架Struts、Hibernate、Spring简单了解
    简单了解ajax
    使用本地计划任务定时关闭azure虚拟机
    调整虚拟机的尺寸
  • 原文地址:https://www.cnblogs.com/gzbnet/p/3194676.html
Copyright © 2020-2023  润新知