【发布时间】:2021-03-02 19:54:06
【问题描述】:
看起来在 .NET 中,基类属性是在属于继承类的属性之后触发的。在我看来,还是我做错了什么?。
我的应用程序中的所有类都继承自具有[AuthorizationAttribute] 的基类,但只有一些类具有[LoggingAttribute]。
当我在 HomeController 中访问方法时,为什么我的 [LoggingAttribute] 在授权之前被命中,我如何才能先触发基类授权属性,然后再触发记录?
[AuthorizationAttribute]
public class BaseController
{
//....class methods
}
[LoggingAttribute]
public class HomeController: BaseController
{
//....class methods
}
属性:
public class AuthorizationAttribute : ActionFilterAttribute
{
//...API token gets parsed into Id/Pw
}
public class LoggingAttribute: ActionFilterAttribute
{
//...Logging record saved with Id/pw established above
}
【问题讨论】:
标签: c# asp.net-mvc inheritance attributes polymorphism