An error occurred while creating a route
Lot of times you make several changes to many files and then you are searching in the Statup.cs in .net core only to end up realizing you messed up an attribute on a new web api method like this
[HttpGet("{id:int")]
As stated in the error message, you have a stray {
in the route template that is making it invalid
template: "{area:my area name}/{{controller=AdminHome}/{action=Index}/{id?}");
^
|
here
You also need to rearrange the order of routes to avoid route conflicts.
app.UseMvc(routes => {
routes.MapRoute(
name: "custom",
template: "{area:my area name}/{controller=AdminHome}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Reference Areas in ASP.NET Core
I am using .Net Core 3.1 Web API project, the problem was in the controller where we specify the route at the the top of the controller, Below is snippet of what was wrong and then what was correct :
ERROR
[Route("api/users/{userId/photos")]
I was missing the closing "}" after userId, which caused this issue.
WORKING
[Route("api/users/{userId}/photos")]
Hope it helps others :)
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index", id = "id?" }
);
routes.MapRoute(
name: "persianredditacp",
template: "{area}/{controller}/{action}/{id?}"
);
THAT worked!