ASP.net MVC Attribute not executed in overridden controller method

I have a custom attribute that gets executed correctly when used in a method of my controller.

My Controller "A" inherits from controller "B" and controller "A" overrides one of the methods on controller "B". I have my own attribute applied to this method, but it doesn't get executed at all. I tried using the basic method, but still.

As noted earlier, a custom attribute is executed as expected when applied in methods that are not overriding.

Did I miss something?

The attribute is executed for the following action method:

    [RequireAuthorizationFor(Operation.Create)]
    public ViewResult New()
    {
        return View("Edit", new TermDateDto());
    }

      

But not for the following:

    [RequireAuthorizationFor(Operation.List)]
    public override ViewResult List(Query query, int? pageNo)
    {
        return base.List(query, pageNo);
    }

      

+2


source to share


1 answer


If it's a custom attribute, is it set to inherit = true?

[AttributeUsage(AttributeTargets.Method, Inherited = true)]

      



Also; possibly a side step; don't make a public method virtual

- call the method instead protected virtual

. A little abstraction goes a long way.

+2


source







All Articles