开发者

ASP.net MVC Attribute not executed in overridden controller method

开发者 https://www.devze.com 2022-12-09 10:40 出处:网络
I have a custom attribute which is executing correctly when used in a method in my controller. My Controller \"A\" is inheriting from Controller \"B\" and Controller \"A\" is overriding one of the me

I have a custom attribute which is executing correctly when used in a method in my controller.

My Controller "A" is inheriting from Controller "B" and Controller "A" is overriding one of the method of Controller "B". I have my custom attribute applied to that method but it's not executing at all. I tried putting in the base method a开发者_如何转开发s well but still same.

As noted earlier, the custom attribute is executing as expected if applied in methods that is not overriding.

Am I missing anything?

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);
    }


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

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

Also; perhaps side-step the issue; don't make the public attributed method virtual - instead make it call a protected virtual method. A little abstraction goes a long way.

0

精彩评论

暂无评论...
验证码 换一张
取 消