Reputation: 55
I have a net web API set up. The URL I want to route to is https://localhost:44378, but Web API forces me to use https://localhost:44378/api/status.
How do I set up a default so if any traffic comes in at https://localhost:44378? redirects to the same code as https://localhost:44378/api/status?
I have tried to use * as the routing default
Upvotes: 0
Views: 557
Reputation: 1161
You should have a WebApiConfig.cs in the App_Start folder of your application.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
.......
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Try removing "api" from the routeTemplate.
For .net core web api, the default is a Route attribute in the controller.
If I use the template to create a Web Api in .Core it gives me a ValuesController.
namespace CoreApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
Just change the route attribute and remove api
[Route("[controller]")]
Upvotes: 1