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
First one should be ActionFilterAttribute, because the OnActionExecuted method does not exiss in IActionFilter
https://msdn.microsoft.com/en-us/library/dd493096(v=vs.118).aspx
https://msdn.microsoft.com/en-us/library/dd493096(v=vs.118).aspx
IAction
but only actionfilteratribute have on result..
ActionFilterAttribute
onactionexecuting
onresultexecuted
The override keywork would not be used with an interface…
There is the point… 🙂
5-1-2
Sorry, i was wrong: 5-1-4: https://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/understanding-action-filters-cs
Kasp are you trying to confuse people on purpose?
Your numbers are wrong.