3 ms·
> // Middleware automatically routes "/Foo" to FooController I don't know why, but I truly do not like this. So if I create a "HelloController" class does the
by whodev 3y ago
> // Middleware automatically routes "/Foo" to FooController
I don't know why, but I truly do not like this. So if I create a "HelloController" class does the middleware just start automatically routing "/hello" to it?
- shortrounddev2 3y agoYes
- halter73 3y agoASP.NET Core can easily route "/hello" to HelloController.Index(), but it's not exactly automatic. The controller library adds routes to the routing middleware in a call to MapControllerRoute the app developer must make during startup which specifies a pattern. app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-7.0#conventional-routing https://learn.microsoft.com/en-us/aspnet/core/mvc/controller... If you don't call one of the MapController methods, requests will not be routed to controllers even if they exist in the same project.