Pregunta

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.

¿Fue útil?

Solución

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 the HomeController.cs file (as well as modify Global.asax.cs to not call RouteConfig.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 when RouteConfig.cs has been removed.

Licenciado bajo: CC-BY-SA con atribución
scroll top