博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Web API]无法添加AttributeRoutes的解决方案
阅读量:3658 次
发布时间:2019-05-21

本文共 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/

你可能感兴趣的文章
【JavaWeb】常见数据库和JDBC错误的解决思路
查看>>
springmvc的静态资源无法访问解决方法(基本全面)
查看>>
【记坑】freemarker拿不到对象的值
查看>>
Maven基础学习(全面)
查看>>
oracle之40道经典的sql练习
查看>>
最详细的Spring-data-jpa入门(一)
查看>>
win7/win10下的jdk的安装和环境变量的配置
查看>>
PAT乙级_1077 互评成绩计算 (20 分)_python
查看>>
PAT乙级_1088 三人行 (20 分)_python
查看>>
PAT乙级_1089 狼人杀-简单版 (20 分)_python
查看>>
PAT乙级_1092 最好吃的月饼 (20 分)_python
查看>>
操作系统页表&进程调度Tips
查看>>
RT-Thread 学习笔记:一、通俗易懂学会创建线程
查看>>
转义序列
查看>>
约分最简分式
查看>>
时间换算
查看>>
逆序的三位数
查看>>
微信小程序学习(二)——WXML
查看>>
JS实现常规登录验证
查看>>
JS下拉框实现省市联动
查看>>