Problem Summary
I’m trying to create custom API controllers in Umbraco 16 but they’re not being discovered/registered by the routing system, returning 404 errors. Even when following the new ASP.NET Core patterns, the controllers aren’t accessible.
Working Environment
- Umbraco Version: 16.0.0
- Target Framework: .NET 9.0
- Project Type: Paul Seal’s Clean Starter Kit for Umbraco 16
- Development Environment: macOS, running on localhost:10311
What Works
Existing API controllers work perfectly:
- http://localhost:10311/api/v1.0/dictionary/getdictionarytranslations returns JSON
- These use the old UmbracoApiController pattern with [MapToApi(“umbraco16cogaiassistant-starter”)]
Service registration works:
- Custom services registered via Composer pattern are working
- Dependency injection functioning correctly
- Umbraco dashboard loads and displays properly
What Doesn’t Work
New API controllers return 404:
- Custom controllers not being discovered
- Both old UmbracoApiController pattern and new ASP.NET Core patterns fail
- Adding endpoints to existing working controllers also fails
Attempts Made
- Traditional UmbracoApiController Pattern (Failed)
[Route("umbraco/api/[controller]/[action]")]
public class TestApiController : UmbracoApiController
{
[HttpGet]
public IActionResult Status() => Ok(new { success = true });
}
Result: 404 on /umbraco/api/TestApi/Status
- Versioned API Pattern (Failed)
[Route("api/v{version:apiVersion}/ai")]
[ApiVersion("1.0")]
[MapToApi("umbraco16cogaiassistant-starter")]
[ApiExplorerSettings(GroupName = "AI Assistant")]
[ApiController]
public class AIAssistantApiV1Controller : UmbracoApiController
{
[HttpGet("ping")]
public IActionResult Ping() => Ok(new { success = true });
}
Result: 404 on /api/v1.0/ai/ping
- Standard ASP.NET Core Pattern (Failed)
[ApiController]
[Route("/api/ai")]
public class AIApiController : Controller
{
[HttpPost("test")]
public IActionResult Test() => Ok(new { success = true });
}
Result: 404 on /api/ai/test
- Adding to Existing Working Controller (Failed)
Added new endpoints to the working DictionaryApiV1Controller:
[HttpGet]
[Route("testai")]
public IActionResult TestAI() => Ok(new { success = true });
Result: 404 on /api/v1.0/dictionary/testai (even though /api/v1.0/dictionary/getdictionarytranslations works)
Current Program.cs Configuration
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Add controllers for AI API
builder.Services.AddControllers();
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddComposers()
.Build();
WebApplication app = builder.Build();
await app.BootUmbracoAsync();
app.UseUmbraco()
.WithMiddleware(u =>
{
u.UseBackOffice();
u.UseWebsite();
})
.WithEndpoints(u =>
{
u.UseBackOfficeEndpoints();
u.UseWebsiteEndpoints();
});
// Map controllers AFTER Umbraco configuration
app.MapControllers();
await app.RunAsync();
Project Structure
- Main Project: Umbraco16CogAIAssistant.Blog (Web project)
- Custom Services: UmbracoAI.Assistant (Class library with controllers)
- Working APIs: Umbraco16CogAIAssistant.Headless (Contains working dictionary API)
The UmbracoAI.Assistant project is properly referenced in the main project.
Specific Questions
- Why do existing controllers work but new ones don’t? Even adding endpoints to working controllers fails.
- Is there a specific registration pattern for Umbraco 16? The documentation mentions moving away from
UmbracoApiController but examples are limited. - Controller discovery issue? Do controllers need to be in specific projects/namespaces?
- Middleware order? Tried MapControllers() both before and after UseUmbraco().
- Missing configuration? Is there additional setup needed for custom API controllers in Umbraco 16?
What I’ve Tried
- Different base classes (UmbracoApiController, Controller, ManagementApiControllerBase)
- Various routing patterns and attributes
- Multiple MapControllers() positions in middleware pipeline
- Adding controllers to different projects in the solution
- Verifying service registration and dependency injection
- Restarting application between changes
Expected Behavior
Custom API controllers should be accessible and return JSON responses, similar to how the existing dictionary API works.
Additional Context
This is for an AI Assistant integration that needs HTTP endpoints for a dashboard interface. The core functionality (OpenAI integration, services, dashboard UI) all work perfectly - only the HTTP API routing is failing.
Any insights into Umbraco 16’s API controller registration mechanism would be greatly appreciated!