Is there something like this for the common method order?
http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-38-WebApiStackDiagramsNew/6428.ASP.NET_5F00_MVC4_5F00_WebAPI_5F00_StackDiagram_5F00_Future.jpg
My Web Api solution has now a new order in the execution of some methods since I upgraded from Beta/RC version to RTM version. (Its not the reverse order of message handler execution)
Earlier this method of the APIControllers was called:
protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext)
{
}
Before the filtermethods of my AuthorizationFilter
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
}
After RTM the OnAuthorization is called before Initialize(). Are there some informations about the execution order of the ApiController methods and the changes after RTM release?
They work similarly in Web API, but controllers in Web API derive from the ApiController class instead of Controller class. The first major difference you will notice is that actions on Web API controllers do not return views, they return data. ApiControllers are specialized in returning data.
Filters get executed in the following order for an action: Globally Defined Filters -> Controller-specific Filters -> Action-specific Filters.
There is indeed no particular ApiController class anymore since MVC and WebAPI have been merged in ASP.NET Core. However, the Controller class of MVC brings in a bunch of features you probably won't need when developing just a Web API, such as a views and model binding.
Web API Controller is similar to ASP.NET MVC controller. It handles incoming HTTP requests and send response back to the caller. Web API controller is a class which can be created under the Controllers folder or any other folder under your project's root folder.
Assuming the request goes into the ApiController scope, the operation order is as below:
ExecuteAsync
method of the ApiController
is invoked.Initialize
method of the ApiController
is invoked.SelectAction
method of the registered action selector is invoked. If only one action method is matched, the pipeline continues.ApiController.ModelState
is set.InvokeActionAsync
method of the registered Action Invoker is called to invoked the selected action method.There are a few more things which happen in between but this is very close to a complete view. Check out the ApiController
source code for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With