Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller level filter stops global filter from executing (MVC3, 2.2+) #18

Closed
pleb opened this issue May 11, 2011 · 1 comment
Closed

Comments

@pleb
Copy link

pleb commented May 11, 2011

A global filter is not executing when a controller contains a controller level filter.

Tried with ninject 2.3.0.6 and 2.2.1.1

To reproduce

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
    public class AlphaAttribute : Attribute {}

    public class FilterAlpha : IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext filterContext) {}

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            filterContext.Controller.ViewData["alpha"] = "here";
        }
    }

    public class FilterBeta : IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext filterContext) {}

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            filterContext.Controller.ViewData["beta"] = "here";
        }
    }

    [Alpha]
    public class WithController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }

    public class WithoutController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }

Registration

            kernel.BindFilter<FilterAlpha>(FilterScope.Controller, 0)
                .WhenControllerHas<AlphaAttribute>();

            kernel.BindFilter<FilterBeta>(FilterScope.Global, 0);

Views

<p>Alpha? @ViewData["alpha"]</p>
<p>Beta? @ViewData["beta"]</p>

Example project can be found here

@remogloor
Copy link
Member

Replaced by ninject/Ninject#36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants