© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
46 replies
Anton

ASP.NET Core routing options

Say, I have a single server for some views and some apis, so I'd route views by default, while the api would go under /api. The question is what's the correct way to achieve the routing?
- Am I supposed to use this https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-6.0#areas , stick an
[Area("api")]
[Area("api")]
on all api controllers?
- Is there a way to have all api controllers be imported from a separate assembly, making them end up in the right grouping on the bases of assembly? Or by namespace prefix?
- Should I explicitly stick a
Route
Route
to all controllers?

So to be a bit more clear, I want my api controllers resolving to
/api/whatever
/api/whatever
, while all the rest should go to
/
/
. I've read the entire page linked above, but it doesn't really mention such a use case, and suggests no best practices in that regard.
Ideally it would be the second option, but the first one also seems fine, if the constant were to be factored out.
Routing to controller actions in ASP.NET Core
Learn how ASP.NET Core MVC uses Routing Middleware to match URLs of incoming requests and map them to actions.
Routing to controller actions in ASP.NET Core
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Asp net core routing
C#CC# / help
4y ago
Routing issue with ASP.Net Core
C#CC# / help
4y ago
❔ ASP.NET routing problem
C#CC# / help
3y ago