Search code examples
c#.netasp.net-mvc-5action-filter

What is the sequence ActionFilter Attribute For Execution?


In ASP.NET MVC which action filter method is executed in sequence wise?

Can anyone tell me the sequence of execution of below method? From top to bottom.

I.e. 1st to last:

OnActionExecuting()
OnActionExecuted()
OnResultExecuted()
OnResultExecuting()

Solution

  • In Asp.Net MVC, ActionFilterAttribute abstract class has the following methods to : These action filter methods are executed by the following sequence,

    1. OnActionExecuting() - Called by the ASP.NET MVC framework before the action method executes.
    2. OnActionExecuted() - Called by the ASP.NET MVC framework after the action method executes.
    3. OnResultExecuting() - Called by the ASP.NET MVC framework before the action result executes.
    4. OnResultExecuted() - Called by the ASP.NET MVC framework after the action result executes.

    You can try this example to track the execution order

    Further read - Msdn