zoukankan      html  css  js  c++  java
  • asp.net form 验证 和取值

      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                              1,                          
                              "ticketName",
                              DateTime.Now,
                              DateTime.Now.AddMinutes(60),
                              false,
                              "{UserNAme:'sanmao'}"
                              );
                    string token = FormsAuthentication.Encrypt(ticket);
                    HttpCookie userCookie = new HttpCookie(FormsAuthentication.FormsCookieName, token);
                    Response.Cookies.Add(userCookie);
                    string url = FormsAuthentication.GetRedirectUrl(UserName, false);//获取来源地址
                    Response.Redirect(url);

     System.Web.HttpContext context = System.Web.HttpContext.Current;

                // 取得用户对象
                System.Security.Principal.IPrincipal user = context.User;

                // 取得用户的角色数组
                System.Web.Security.FormsIdentity fi = user.Identity as System.Web.Security.FormsIdentity;

                // 取得用户的票据
                System.Web.Security.FormsAuthenticationTicket ticket = fi.Ticket;

                // 创建用户所拥有的角色数组
                string roleString = ticket.UserData;

                // 还原为字符串数组
                string[] roleArray = { roleString };//roleString.Split(',');


                // 自己创建用户对象
                System.Security.Principal.GenericPrincipal principal
                    = new System.Security.Principal.GenericPrincipal(
                        user.Identity,
                        roleArray
                        );
                // 让系统使用我们的拥有角色的用户对象
                context.User = principal;

                Response.Write(tt);

  • 相关阅读:
    迁移服务器遇到django-crontab不执行定时任务问题
    纯CSS3+DIV实现小三角形边框
    mysql密码错误-ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor:yes)
    收货地址下边的平行四边形彩色线条
    小程序导航栏全屏navigationStyle自定义导航栏,小程序轮播图导航栏
    移动宽带下Github网页上不去的解决办法
    线段比例式或等积式的证明思路
    两角不等的证明思路
    线段不等的证明思路
    两角相等的证明思路
  • 原文地址:https://www.cnblogs.com/wanyuan8/p/2508045.html
Copyright © 2011-2022 走看看