c# - Are all phases of an ActionFilterAttribute guaranteed to be called? -
c# - Are all phases of an ActionFilterAttribute guaranteed to be called? -
in writing this answer, asked if there guarantees behaviour of actionfilterattribute. , unable reply confidence.
in particular, 4 of methods onactionexecuted, onactionexecuting, onresultexecuted & onresultexecuting guaranteed called requests pass through attribute, or there circumstances (such exceptions, dropped connection etc) 1 or more of phases might not fire?
no not guaranteed called.
think of authorization filters. if authorization fails, expect action filters run? big security hole. believe exception stop pipeline of filters , exception filters executed point.
given next filter:
public class examplefilterattribute : filterattribute, iactionfilter { public void onactionexecuted(actionexecutedcontext filtercontext) { // code never reached... } public void onactionexecuting(actionexecutingcontext filtercontext) { throw new notimplementedexception(); } } on next controller action:
[examplefilter] public actionresult index() { // code never reached... homecoming view(); } neither index() method or onactionexecuted() ever reached because onactionexecuting() has exception.
c# asp.net-mvc asp.net-mvc-5 actionfilterattribute
Comments
Post a Comment