What is the difference between WebApiConfig.cs
and RouteConfig.cs
in the App_Start
folder of an MVC Web API project in Visual Studio 2012?
The WebApiConfig. cs is configuration file for Web API. You can configure routes and other things for web API, same like RouteConfig. cs is used to configure MVC routes. It also creates Web API controller ValuesController.
In MVC, routing is a process of mapping the browser request to the controller action and return response back. Each MVC application has default routing for the default HomeController. We can set custom routing for newly created controller. The RouteConfig. cs file is used to set routing for the application.
As you can see above, WebApiConfig. Register() method includes a parameter of HttpConfiguration type which is then used to configure the Web API. The HttpConfiguration is the main class which includes following properties using which you can override the default behaviour of Web API.
Every MVC application must configure (register) at least one route configured by the MVC framework by default. You can register a route in RouteConfig class, which is in RouteConfig. cs under App_Start folder. The following figure illustrates how to configure a route in the RouteConfig class .
The following are the key differences:
As cmotley mentions, the ASP.NET web site includes a good listing of what types of configuration can be done in WebApiConfig.cs in this article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With