本文共 1574 字,大约阅读时间需要 5 分钟。
1.按照微软官方文档,如果要使用AttributeRoutes,需要在APP_START里的WebApiConfig.cs的Register方法中添加一行:config.MapHttpAttributeRoutes();
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 } ); // 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(); // 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,输入如下命令:
Install-Package Microsoft.AspNet.WebApi.WebHost
运行完毕,重启VS,小红线是不是神奇的消失啦,啦啦啦
2.升级之后会遇到一些问题,比如后来写代码运行的时候,又出问题了,报错信息如下:
'CommonServices.Areas.HelpPage.XmlDocumentationProvider' does not implement interface member
解决方法,仍然是调出package manager console,运行如下命令:
install-package Microsoft.AspNet.WebApi.HelpPage
问题解决啦
转载地址:http://abafn.baihongyu.com/