Exemplo n.º 1
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            _permissionService =
                (IPermissionServices)context.HttpContext.RequestServices.GetService(typeof(IPermissionServices));
            if (context.HttpContext.User.Identity.IsAuthenticated)
            {
                string userName = context.HttpContext.User.Identity.Name;

                if (!_permissionService.CheckPermission(_permissionId, userName))
                {
                    context.Result = new RedirectResult("/Login?" + context.HttpContext.Request.Path);
                }
            }
            else
            {
                context.Result = new RedirectResult("/Login");
            }
        }