문제

I'm writing an ActionFilter to check for some cookies before executing the action (overriding OnActionexecuting.
No problem here, but I'm wondering whether it is necessary or recommended to call the base method? I haven't done so in previous filters I've written, without noticeable effects, but I've seen sample code around the net that leaves base.OnActionExecuting(filterContext) before leaving the method.
Is there any reason to do so? The MSDN page does not say anything the base method does.

(using ASP.Net MVC 4 / Razor engine, if that's relevant).

도움이 되었습니까?

해결책

When talking about just ordinary ActionFilterAttributes the OnActionExecuting and the other virtual methods are empty as shown in the source here.

So, it doesn't matter if you call the base method or not. But to avoid introducing future possible changes in upcoming versions in the base methods I'd actually not call base if not needed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top