1.按照微软官方文档,若是要使用AttributeRoutes,须要在APP_START里的WebApiConfig.cs的Register方法中添加一行:config.MapHttpAttributeRoutes();web
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);api
// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable return type.
// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
//config.EnableQuerySupport();app
// To disable tracing in your application, please comment out or remove the following line of code
// For more information, refer to: http://www.asp.net/web-api
config.EnableSystemDiagnosticsTracing();
}
可是我加了以后死命报错,划小红线,嘤嘤嘤
后来查到解决方法,是由于属性路由是WebAPI 2中才加的,须要将VS升级到WebAPI 2。在菜单栏Tools-->NuGet package manager--->package manager console,输入以下命令:asp.net
Install-Package Microsoft.AspNet.WebApi.WebHostide
运行完毕,重启VS,小红线是否是神奇的消失啦,啦啦啦.net
2.升级以后会遇到一些问题,好比后来写代码运行的时候,又出问题了,报错信息以下:code
'CommonServices.Areas.HelpPage.XmlDocumentationProvider' does not implement interface member orm
解决方法,仍然是调出package manager console,运行以下命令:blog
install-package Microsoft.AspNet.WebApi.HelpPageci