Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top