I have create an "ASP.NET Core Web App" Project in Visual Studio.
I want to add an API in this project ? I can create a separate Web API project but i want to put everything in the same project.
Is it possible ?
Thanks
If you want to keep the web app project and also add a few API endpoints you could just add a folder (e.g. Api) at the project root where you can place your api-controllers.
Then in that folder you can add a class that will derive from ControllerBase and decorate it with [ApiController] attribute and a [Route] attribute.
This requires configuration of controllers in your Startup.cs though:
ConfigureServices() add a call to services.AddControllers();Configure specify the MapControllers() option:app.UseEndpoints(endpoints => {
// other code
endpoints.MapControllers();
});
I would suggest you build an API solution, and then a separate Core Web App solution.
Otherwise you could try starting with a 'Blank Solution' and adding different projects to it.
Is it possible ?- Yes.