Exemplo n.º 1
0
        /// <summary>
        /// Called before the action method is invoked.
        /// </summary>
        /// <param name="filterContext">Information about the current request and action.</param>
        protected override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
        {
            // Check permissions
            var attrs = filterContext.GetType().GetCustomAttributes(typeof(Library.Attributes.Permission), true);

            if (attrs.Any())
            {
                foreach (var attrP in
                         attrs.Select(attr => (attr as Library.Attributes.Permission)).
                         Where(attrP => attrP != null && attrP.HasPermission(attrP.Value1, attrP.Value2, attrP.Value3, attrP.Value4) == false))
                {
                    if (Mtn.Library.Web.Utils.Parameter.UnallowedPage.IsNullOrWhiteSpaceMtn())
                    {
                        string msg = PermissionErrorMessage;
                        if (msg.IsNullOrWhiteSpaceMtn())
                        {
                            msg = (string)Library.Attributes.Permission.UnallowedResult;
                        }

                        if (msg.IsNullOrWhiteSpaceMtn())
                        {
                            msg = new DataPage <string>().GetUnallowedPage().Message;
                        }

                        if (msg.IsNullOrWhiteSpaceMtn())
                        {
                            WriteStatisc("PermissionCheck", "You don't have permission to see this page/action!");
                        }
                        else
                        {
                            WriteStatisc("PermissionCheck", msg);
                            Response.Write(msg);
                        }
                        _supressContent = true;
                    }
                    else
                    {
                        WriteStatisc("PermissionCheck", string.Format("Redirecting to -> {0}", Mtn.Library.Web.Utils.Parameter.UnallowedPage));
                        _supressContent = true;
                        Response.Redirect(Mtn.Library.Web.Utils.Parameter.UnallowedPage, true);
                    }
                }
            }
            if (_supressContent == false)
            {
                base.OnActionExecuting(filterContext);
            }
        }