Before reading this article, I highly recommend you read the previous parts of the article series:
However, I do recommend to refer the previous articles of MVC Life Cycle series. This will help you a ton in understanding the concepts at its core. Here, in this case we will see
Filters in action. Therefore, before the action method chosen, the
Authentication and Authorization filter runs. Filters are nothing but MVC components to inject extra logic in between the
MVC pipeline.Therefore, first authentication filter runs and if it succeeds then it will go to
Authorization filter otherwise it will again ask user to re-authenticate. However, authorization is the filter which says are you allowed to access particular thing or not.
At this stage, all authentication and authorization got succeeded which means, it will move to next step of pipeline wherein
action invoker will pick the method to execute, but before execution it needs to populate data for
Model Binding. Model Binding is the process of taking data from different data sources say
Form Data, Query-String etc and create objects for action method parameters. Once, the parameters get populated then another set of action filters get executed which is associated with controllers itself like
OnActionExecuting or
OnActionExecuted. Therefore, before actual method gets invoked
OnActionExecuting filter will run and after that the later one. After this entire exercise,
Action Method will finally get called. Now, Action Methods after running will return Action Results. Now, there are variety of Action Results like
JSON-Result, View Result, etc. Also, based on this Action Result it will generate the actual
HTTP-Response for the
HTTP-Request. This is just the brief snapshot around the Action Execution.
Therefore
ActionInvoker is basically responsible for generating response. Again like many other MVC components,
ActionInvoker also implements
IActionInvoker which has only one method
InvokeAction. However, you can also extend the same and create your own ActionInvoker which handles the request in custom way. But, as I mentioned earlier
ASP.NET MVC is really powerful framework where in all the concerns are already addressed. So, I don't see any reason for doing this. Now, let us talk about Model Binders in detail.
Model Binders fetch data from
Value Providers. Below, I have mentioned the list of the same.
interface. This Interface also implements one method called
. As we know that Model Binders run in between different filters. Hence, it would be good idea to talk about filters in detail.
With the above change in place, when I run the app, it will produce the following output.
I hope you have liked this discussion. Thanks for joining me.