zoukankan      html  css  js  c++  java
  • 曾经用过的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);
                }
            }

     

  • 相关阅读:
    Intellij IDEA 使用jrebel运行spring-boot并实现自动编译进行热部署
    eclipse常见问题解决方案
    Spring Boot 打包部署
    解决oracle数据库 ora-00054:resource busy and acquire with NOWAIT specified 错误
    java RSA加密解密实现(含分段加密)
    Spring bean作用域
    博客目录
    分析SQL执行效率(一)
    索引操作
    表的基本操作
  • 原文地址:https://www.cnblogs.com/gzbnet/p/3194676.html
Copyright © 2011-2022 走看看