ControllerBase in ASP.NET MVC contains three methods:
I couldn’t find a lot of information about these. Just advice to use Initialize instead of Execute. Could anybody know the purposes of these methods? And in which case they should be used according to good practices?
The
Executemethod is the one that comes from theIControllerinterface and that all controllers posses. In the default implementation (ControllerBase) the Execute method first calls theInitializemethod and then theExecuteCoremethod. The Initialize method is where the context becomes available. This is the earliest method in the pipeline execution where you can access the HttpContext related stuff. For example if you attempt to access it in a controller’s constructor you will get a NRE. TheExecuteCoremethod is responsible for loading the TempData, finding and executing the correct action to execute given theactionroute data value and finally saving the TempData.