Hi, I have created a new ASP.NET Core (5.0) Web API project. When I run the project from command line, I get 404 not found error since there are no redirects configured. I have created a HomeController, with the route as api/Home. I want to redirect to the
default Index method in HomeController when I run from command line.
I also tried editing launchSettings.json and added api/Home in launchUrl, even this didn't work. When I manually try to go to
https://localhost:5001/api/home, it works.</div> <div>Is there a way using which I can route to a controller's method when "/" route is hit?
Hi, I have created a new ASP.NET Core (5.0) Web API project.
Web API does not have a UI. The default Web API template displays a swagger documentation page. Can you explain the design intent? Perhaps you want MVC not Web API?
yes you are right, apis don't need a home page or anything but something is better than 404. The swagger endpoint is also not working as a default route when set from launchSettings in launchUrl: "swagger". When navigated manually, it works.
None
0 Points
8 Posts
How to route to an endpoint from "/" route?
Mar 07, 2021 04:00 PM|temp_learner|LINK
Hi, I have created a new ASP.NET Core (5.0) Web API project. When I run the project from command line, I get 404 not found error since there are no redirects configured. I have created a HomeController, with the route as api/Home. I want to redirect to the default Index method in HomeController when I run from command line.
I tried adding:
But it didn't redirect.
I finally ended up writing:
I also tried editing launchSettings.json and added api/Home in launchUrl, even this didn't work. When I manually try to go to https://localhost:5001/api/home, it works.</div> <div>Is there a way using which I can route to a controller's method when "/" route is hit?
All-Star
53641 Points
24010 Posts
Re: How to route to an endpoint from "/" route?
Mar 07, 2021 04:12 PM|mgebhard|LINK
Web API does not have a UI. The default Web API template displays a swagger documentation page. Can you explain the design intent? Perhaps you want MVC not Web API?
None
0 Points
8 Posts
Re: How to route to an endpoint from "/" route?
Mar 08, 2021 04:50 AM|temp_learner|LINK
yes you are right, apis don't need a home page or anything but something is better than 404. The swagger endpoint is also not working as a default route when set from launchSettings in launchUrl: "swagger". When navigated manually, it works.