- ASP.NET Core MVC
- ASP.NET Core logging with Serilog
- ASP.NET Core managed config
- ASP.NET Core MVC with /api/-area
- ASP.NET Core API versioning
- ASP.NET Core API with Swagger UI
- ASP.NET Core EF in separate project
- ASP.NET Core AutoMapper
- ASP.NET Core response cache
- ASP.NET Core memory cache
- ASP.NET Core TypeScript
Having MVC pages and API in the same solution can be beneficial. Projects may share a lot of boilerplate code and settings, is easier to maintain and can access API functions directly through DI (if controllers are registered there) instead of going via HTTP. But you may want to separate both URL and code so it is clear what is MVC and what is API.
Setting up areas
If you are using Visual Studio: Right-click project, select Add, select Area, enter “api”. This will create empty folder Areas\api with MVC folder structure under it. It also pops up a text file asking you to make a change to the default MapRoute in Startup.cs.
If using Rider or other tool you may have to do it manually. Create folders in root:
Then in addition to your existing default route, you should add areas route in Startup.cs.
Adding Api controller
Again, if you are using Visual Studio, simply:
- Right click “Areas\Api\Controllers”
- Select “Add->Controller”
- Select “API Controller – Empty” and name it, for this test I named it TestController
If you are using Rider or other tool you may have either create manually (see bellow for sample) or create Controller and modify it a bit. Change “Controller” to “ControllerBase”, add [ApiController] tag and set route.
In the newly created TestController.cs we need to specify route, specifically [action]. This can be done in class route definition, or per method. With a few example methods the class looks like this:
public class TestController : ControllerBase
public string Concat(string a, string b)
return a + b;
public string GetOnly()
return "Can't post here";
public string DualGet()
return "You used GET";
public string DualPost()
return "You used POST";
public IActionResult ReturnHttpCode(int id)
return Ok("You found it!");
You can then test this by starting solution and opening browser to https://localhost:44378/Api/Test/Concat/123/abc. Note that you must change port number to whatever port your solution is running on.