locked
ActionFIlterAttribute RRS feed

  • Question

  • User527076549 posted

    Before an action is executed, information about the action must be written to a log. After results
    are returned, information about the results also must be written to the log.
    You need to log the actions and results

    what shoul be the answers for target1 and target2

    Before action executed =         OnActionExecuting(ActionExecutingContext filterContext)

    after result returned = once action executed you get the result ,so "OnActionExecuted(ActionExecutedContext filterContext)"

    Can anyone tell me if i am right or wrong ?

    you can get result in  OnResultExecuting in as well ..


    public class LogActionFilter : ActionFilterAttribute { public override void TARGET1 { Log("LOGACTION", filterContext.RouteData); } public override void TARGET2 { Log("LOGRESULT", filterContext.RouteData); } }

    I really appreciate your help.Thank you

    Saturday, October 5, 2019 4:35 AM

All replies

  • User-17257777 posted

    Hi amithashenoy,

    Yes, you are right. The base ActionFilterAttribute class has the following methods that you can override:

    • OnActionExecuting – This method is called before a controller action is executed.
    • OnActionExecuted – This method is called after a controller action is executed.
    • OnResultExecuting – This method is called before a controller action result is executed.
    • OnResultExecuted – This method is called after a controller action result is executed.

    For more, you can refer to

    https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.actionfilterattribute?view=aspnet-mvc-5.2

    Best Regards,

    Jiadong Meng.

    Monday, October 7, 2019 6:51 AM
  • User-1151440187 posted

    ActionFilterAttribute abstract class includes the following methods to override:

    • void OnActionExecuted(ActionExecutedContext filterContext)
    • void OnActionExecuting(ActionExecutingContext filterContext)
    • void OnResultExecuted(ResultExecutedContext filterContext)
    • void OnResultExecuting(ResultExecutingContext filterContext)
    Monday, October 21, 2019 4:40 AM