Antoine
Antoine

Reputation: 5245

Is there a need to call the base methods when writing an ActionFilter?

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).

Upvotes: 0

Views: 407

Answers (1)

Riri
Riri

Reputation: 11947

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.

Upvotes: 1

Related Questions