I m working on Web API project, and it is using WebApiConfig.cs
file to defined routs for Web API.
Web API fold RouteConfig.cs
file. I have googled and they say RouteConfig.cs
is for MVC routing. It is actually a confusing statement. Can you please guide why WebAPI has RouteConfig.cs
file ? Why would one need MVC routing in Web API ? What function it will do ?
Thanks for your help and guidance.
Best Answer
The
RouteConfig.cs
file isn't required for Web API. It is included by default in new Web API projects because that template also includes an MVC webpage (for the index page that appears when you open the project in a browser).If you delete both the
RouteConfig.cs
and theHomeController.cs
file (as well as modifyGlobal.asax.cs
to not callRouteConfig.RegisterRoutes()
), then your project will still compile and the API controllers will still work fine, you will just be missing a pretty homepage.Note also that MVC Areas have their own MVC routing and do not use the global MVC routing, which is why the
/Help
page still works even whenRouteConfig.cs
has been removed.