Esempio n. 1
0
        /// <summary>
        ///根据HttpContext对象设置用户标识对象
        /// </summary>
        /// 时间:2016-04-29 11:28
        /// 备注:
        public static void SetUserInfo()
        {
            FormsPrincipal <T> _user = ParsePrincipal();

            if (_user != null)
            {
                HttpContext.Current.User = _user;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 用户权限初始化
        /// </summary>
        /// <param name="roles">用户隶属的权限组</param>
        /// 时间:2016-04-29 11:25
        /// 备注:在 Application_AuthenticateRequest()中使用
        public static void AddPermission(string[] roles)
        {
            HttpContext _context = HttpContext.Current;

            if (!_context.Request.IsAuthenticated)
            {
                return;
            }
            if (HttpContext.Current.User.Identity is FormsIdentity)
            {
                FormsPrincipal <T> _curPrincipal = ParsePrincipal();
                if (_curPrincipal != null)
                {
                    HttpContext.Current.User = new GenericPrincipal(_curPrincipal.Identity, roles);
                }
            }
        }