PrepAway - Latest Free Exam Questions & Answers

Which code segments should you include in Target 1, Tar…

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.)
Hot Area:

PrepAway - Latest Free Exam Questions & Answers

Answer:

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 itis 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

4 Comments on “Which code segments should you include in Target 1, Tar…

  1. Muthukumar says:

    Target 1 => Should be :

    public class LogActionFilter:ActionFilterAttribute

    Because IActionFilter Interface doesn’t have OnResultExecuted
    From the question
    ” After results are returned information about the results also must be written to the log.”

    Also Target 3 has “OnResultExecuted(ResultExecutedContext)”




    11



    0
  2. Ajaz says:

    Target # 1 : public class LogActionFilter : ActionFilterAttribute
    Target # 2 : OnActionExecuting(ActionExecutingContext filterContext)
    Target # 3 : OnResultExecuted(ResultExecutedContext filterContext)




    30



    0

Leave a Reply