Exemplo n.º 1
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            try
            {
                if (httpContext.Session == null)
                {
                    return(false);
                }
                LocalUser myuser = (LocalUser)httpContext.Session["myuser"];
                if (myuser == null)
                {
                    return(false);
                }
                if (!myuser.IsAuthenticated)
                {
                    return(true);
                }

                if (!string.IsNullOrWhiteSpace(this.Roles))
                {
                    if (!myuser.IsInRole(this.Roles))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }