为什么要调用base.OnActionExecuting(filterContext);? [英] Why call base.OnActionExecuting(filterContext);?

查看:295
本文介绍了为什么要调用base.OnActionExecuting(filterContext);?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是看一些我的旧代码,我有一个动作过滤器(OnActionExecuting方法)

I am just looking at some old code of mine and I have an action filter(OnActionExecuting method)

最后我有

 base.OnActionExecuting(filterContext); 

为什么要四处搜寻,所以我看到了好几次.我还看到在旧的Authorize标签中,我称它为基础.

Why searching around I see this quite a few times. I also see that in my old Authorize tag I call the base up.

我以后应该一直调用基本方法吗?

Should I be always be calling the base methods after?

推荐答案

我以后应该一直调用基本方法吗?

Should I be always be calling the base methods after?

这取决于情况.

例如,在授权过滤器(源自AuthorizeAttribute)中,如果调用基本方法,则将执行ASP.NET MVC中内置的所有现有授权逻辑.如果您不调用它,则只会应用您的授权逻辑.

For example in authorization filters (deriving from AuthorizeAttribute) if you call the base method then all the existing authorization logic built into ASP.NET MVC will be executed. If you don't call it, only your authorization logic will be applied.

就其他标准动作过滤器而言(源自ActionFilterAttribute),所有OnActionExecutingOnActionExecutedOnResultExecutingOnResultExecuted均定义为虚拟,但其主体为空,因此它不是不管您是否调用基本方法,都不会有所不同.

As far as other standard action filters are concerned (deriving from ActionFilterAttribute) all the OnActionExecuting, OnActionExecuted, OnResultExecuting and OnResultExecuted are defined as virtual but their body is empty, so it doesn't make any difference if you call or not the base method.

这篇关于为什么要调用base.OnActionExecuting(filterContext);?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆