zoukankan      html  css  js  c++  java
  • 【Web API]无法添加AttributeRoutes的解决方案

    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

    问题解决啦
    ---------------------
    作者:missyr
    来源:CSDN
    原文:https://blog.csdn.net/qingtian12138/article/details/73857018
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    Android集成科大讯飞SDK语音听写及语音合成功能实现
    Android开发中一些常见的问题解决方案
    Android混淆配置文件规范
    android第三方分享之友盟社会化组件
    android一些常用的代码2(收藏)
    svn
    ubuntu 解决中文zip乱码问题
    android优秀Github源码整理
    linux清理内存
    cocos2d-x图层相关 锚点
  • 原文地址:https://www.cnblogs.com/Jeely/p/10956747.html
Copyright © 2011-2022 走看看