BlogEngine.Core.Security.IsAuthorizedTo C# (CSharp) Метод

IsAuthorizedTo() публичный статический Метод

Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck.
public static IsAuthorizedTo ( AuthorizationCheck authCheck ) : bool
authCheck AuthorizationCheck
Результат bool
        public static bool IsAuthorizedTo(AuthorizationCheck authCheck, params Rights[] rights)
        {
            return IsAuthorizedTo(authCheck, rights.ToList());
        }

Same methods

Security::IsAuthorizedTo ( AuthorizationCheck authCheck, IEnumerable rights ) : bool
Security::IsAuthorizedTo ( Rights right ) : bool

Usage Example

Пример #1
0
        /// <summary>
        /// Returns whether the SiteMapNode is accessible to the current user.
        /// </summary>
        public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
        {
            // We are only checking Rights here.  Roles may also be part of
            // the SiteMapNode.  Let the base class check for that.  If false,
            // return false, otherwise, continue with our check of Rights.

            if (!base.IsAccessibleToUser(context, node))
            {
                return(false);
            }

            if (!Utils.StringIsNullOrWhitespace(node["rights"]))
            {
                // By default, all specified Rights must exist.
                // We allow this to be overridden via the "rightsAuthorizationCheck"
                // attribute.

                AuthorizationCheck authCheck = AuthorizationCheck.HasAll;
                if (!Utils.StringIsNullOrWhitespace(node["rightsAuthorizationCheck"]))
                {
                    authCheck = Utils.ParseEnum <AuthorizationCheck>(node["rightsAuthorizationCheck"], AuthorizationCheck.HasAll);
                }

                string[] rightsRaw = node["rights"].Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);

                List <Rights> rightsToCheck = new List <Rights>();
                foreach (string r in rightsRaw)
                {
                    Rights right = Utils.ParseEnum <Rights>(r.Trim(), Rights.None);
                    if (right != Rights.None)
                    {
                        rightsToCheck.Add(right);
                    }
                }

                if (rightsToCheck.Count > 0)
                {
                    return(Security.IsAuthorizedTo(authCheck, rightsToCheck.ToArray()));
                }
            }

            return(true);
        }
All Usage Examples Of BlogEngine.Core.Security::IsAuthorizedTo