I am following a tutorial to build Web API Application, but I do not understand from which class a controller has to inherit.
In my tutorial is explained to inherit from ControllerBase, but around the web I saw that Controller who inherit from ApiController.
What is the best path to follow?
CodePudding user response:
"I am following a tutorial to build Web API Application, but I do not understand from which class a controller has to inherit?"
First of All you didn't shared which document you are following, on the other than it depends which kind of
asp.netorasp.net coreprojectcontrolleryou have taken. For example if you have takenasp.net core controllerit should be inherited fromControllerBaseif you have takenasp.net MVCit should be inherited fromControllerbut if you have taken onlyasp.net web API controllerit should be inherited fromApiControlleras you may know
Asp.net Core MVC Controller Inherited From Controller:Developed on
asp.net core MVC
Asp.net Core Controller Inherited From ControllerBase:All
asp.net coreno matterMVCorWeb APIInherited from ControllerBase. After release version of asp.net core 2.1, you wouldn't get anything InheritedApiControllerall fromControllerBaseand curently on.Net 5.0or.Net 6.0
"In my tutorial is explained to inherit from ControllerBase, but around the web I saw that Controller who inherit from ApiController?"It depends on which version of
asp.netorasp.net coreproject you are working on. If you are usingasp.net core 5.0or latter than it should useControllerBaseby default as convension.Note: If you would like to know more details on diffrent kind of
ASP.NET MVC and Web API with controllers or even ASP.NET Coreyou can check here our official documentHope it would guided you accordingly.



