Which code segments should you include in Target 1, Target 2 and Target 3 to implement the LogActionFilter class?

HOTSPOT
You are developing an ASP.NET MVC application.
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.
You have the following code:

Which code segments should you include in Target 1, Target 2 and Target 3 to implement the
LogActionFilter class? (To answer, select the appropriate option from the drop‐down list in the
answer area.)



HOTSPOT
You are developing an ASP.NET MVC application.
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.
You have the following code:

Which code segments should you include in Target 1, Target 2 and Target 3 to implement the
LogActionFilter class? (To answer, select the appropriate option from the drop‐down list in the
answer area.)



Answer: See the explanation

Explanation:



Target 1: IActionFilter
MVC3 introduced a completely new pattern to configure filters for controllers and its actions. While
injection of filter attributes is still supported it is recommended using this new pattern for filter
configuration because it has the advantage to support constructor injection and does not require the
InjectAttribute anymore.
First of all you have to create your filter class by implementing one of the filter interfaces e.g.
IActionFilter.
Target 2: public void OnActionExecuting(ActionExecutingContext filterContext)
Target 3: public void OnActionExecuted(ActionExecutedContext filterContext)
Dependency injection for filters
https://github.com/ninject/Ninject.Web.Mvc/wiki/Dependency‐injection‐for‐filters



Leave a Reply 9

Your email address will not be published. Required fields are marked *


Scar

Scar

First one should be ActionFilterAttribute, because the OnActionExecuted method does not exiss in IActionFilter