Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between WebApiConfig.cs and RouteConfig.cs

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?

like image 518
shiv455 Avatar asked Feb 22 '13 05:02

shiv455


People also ask

What is WebApiConfig CS?

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.

What is RouteConfig CS?

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.

What is use of WebApiConfig?

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.

Where is RouteConfig CS?

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 .


1 Answers

The following are the key differences:

  1. RouteConfig.cs is exclusively for configuring ASP.NET routes.
  2. WebApiConfig.cs is for any Web API related configuration, including Web-API-specific routes, Web API services, and other Web API settings.

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.

like image 139
Eilon Avatar answered Sep 28 '22 08:09

Eilon