Difference between WebApiConfig.cs and RouteConfig.cs

后端 未结 3 1269
长情又很酷
长情又很酷 2021-02-11 13:28

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?

相关标签:
3条回答
  • 2021-02-11 13:50

    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.

    0 讨论(0)
  • 2021-02-11 14:04

    If you are familiar with ASP.NET MVC, Web API routing is very similar to MVC routing. The main difference is that Web API uses the HTTP method, not the URI path, to select the action. You can also use MVC-style routing in Web API. This article does not assume any knowledge of ASP.NET MVC.

    From Routing in ASP.NET Web API

    0 讨论(0)
  • 2021-02-11 14:05

    There is no difference as they both accomplish the same thing - adding routes to your route collection. You don't need to use the WebApiConfig class; it's simply a convenient way to organize your code.

    0 讨论(0)
提交回复
热议问题