I’m preparing to Microsoft Certificate exam (70-515), reading Microsoft book for this exam, practicing tests… one tests asks:
You are creating a custom MVC action filter to cache action results.
Which virtual method should you override?
Correct answer (according to test program, that is distributed with a book) is "OnResultExecuting"
And explanation for the answer:
When you create a custom action filter by inheriting from the ActionFilterAttribute class, you can override four virtual methods that run in the following order: OnActionExecuting(), OnActionExecuted(), OnResultExecuting(), and OnResultExecuted(). For output caching, you want to capture the final rendered results. Therefore, you should override the last method to run: OnResultExecuting().
Here is inconsistency: If we need to override the LAST mentioned method, then it should be "OnResultExecuted". But in answer it is told "OnResultExecuting".
So the question is:
- What is a CORRECT method to be overridden?
- Which option should I choose on exam to get answer considered as correct? (Question is valid for case when "correct" answer is actually different from suggested by system.
Thanks.
P.S. I not sure if current question belongs to SO, but at least it is pretty close
After some time for me it made some sense: You should override ‘OnResultExecuting’ method in order to check if you have already result cached. If “yes” you will just get it from cache, if no, you will really execute functionality of “executing” part and then put it to cache.