❔ ASP .NET Core Controller Default Route Issue
I have a controller (TestController) with an Index action method.
The url I'm using is "localhost:8372/Test"
This returns a 404 error
If I add
[Route("[controller]")]
the controller works as expected.
I just created the application but I thought that [Route("[controller]")]
was the default route. Is it not?9 Replies
Route("[controller]")
Means the route would be bound to this class' name (the class annotated with the attribute)
Notice controller
is between []
yeah I see that but isn't that how it normally is?
I swear you could create a controller called "RaccoonController" and the path would default to /controller/action
or in this case /raccoon/action
You want this?
Route("[controller]/[action]")
that's what this does
I want to know what the default is, because I swear what I added is just the same as the default
I'm confused right now, sorry wdym by default 😅 ?
default for what?
you don't have to specify a path on the controller
Oh!
If your controller has
ApiController
attribute then you must add Route
attribute afaik, but if the controller doesn't have ApiController
you can do something like
app.MapControllerRoute("default", "{controller=Home}/{action=Get}");
okay well good news this does work, I'm still confused as to what the default mapping is, and if they just removed it?
I feel like there's no way they completely removed it but for now this is a nice implementation so thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.