asp.net-mvc WebApiConfig.cs 和 RouteConfig.cs 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15017188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between WebApiConfig.cs and RouteConfig.cs
提问by shiv455
What is the difference between WebApiConfig.csand RouteConfig.csin the App_Startfolder of an MVC Web API project in Visual Studio 2012?
Visual Studio 2012 中 MVC Web API 项目的文件夹WebApiConfig.cs和文件夹之间有什么区别?RouteConfig.csApp_Start
采纳答案by Eilon
The following are the key differences:
以下是主要区别:
- RouteConfig.cs is exclusively for configuring ASP.NET routes.
- WebApiConfig.cs is for any Web API related configuration, including Web-API-specific routes, Web API services, and other Web API settings.
- RouteConfig.cs 专门用于配置 ASP.NET 路由。
- WebApiConfig.cs 用于任何与 Web API 相关的配置,包括特定于 Web-API 的路由、Web API 服务和其他 Web API 设置。
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.
正如 cmotley 所提到的,ASP.NET 网站很好地列出了本文的WebApiConfig.cs 中可以完成的配置类型。
回答by Eilon
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.
没有区别,因为它们都完成相同的事情 - 将路线添加到您的路线集合中。您不需要使用 WebApiConfig 类;它只是一种组织代码的便捷方式。
回答by redcalx
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.
如果您熟悉 ASP.NET MVC,Web API 路由与 MVC 路由非常相似。主要区别在于 Web API 使用 HTTP 方法而不是 URI 路径来选择操作。您还可以在 Web API 中使用 MVC 风格的路由。本文不假设您对 ASP.NET MVC 有任何了解。

