asp.net-web-api – Web API帮助页面始终为空

我已经添加了帮助页面Nuget包来为我的Web API创建文档,但它对我不起作用,没有显示API方法.

我没有注释:

config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));

我检查了框XML文档文件并设置了App_Data / XmlDocument.xml的路径

我没有使用Glimpse,因为这里有许多解决方案.

我甚至在授权的帮助页面上安装了nuget包,但它没有帮助

这有什么问题?如果我开始空项目而不是工作正常,但这个API太大了,无法重新开始.

解决方法

如果您使用OWIN作为中间件(就像我一样),您可能正在初始化其启动方法中的新HttpConfiguration.问题是HelpController和HelpPageConfig正在使用GlobalConfiguration.Configuration,这似乎是错误的.是什么帮助了我:

第1步:使启动HttpConfiguration成为静态字段

[assembly: OwinStartup(typeof(MyProject.API.Startup))]
namespace MyProject.API
{
    public class Startup
    {
        //new
        public static HttpConfiguration HttpCfg;
        //

        public void Configuration(IAppBuilder app)
        {
            HttpCfg = new HttpConfiguration();
            WebApiConfig.Register(HttpCfg);
            app.UseWebApi(HttpCfg);

            AreaRegistration.RegisterallAreas();
        }
    }
}

第2步:转到HelpPageAreaRegistration并编辑Registerarea方法

public override void Registerarea(AreaRegistrationContext context)
{
    context.MapRoute(
        "HelpPage_Default","Help/{action}/{apiId}",new { controller = "Help",action = "Index",apiId = UrlParameter.Optional });

    //old
    //HelpPageConfig.Register(GlobalConfiguration.Configuration);

    //new
    HelpPageConfig.Register(Startup.HttpCfg);
}

第3步:转到HelpController并像这样编辑标准构造函数

//old
//public HelpController() : this(GlobalConfiguration.Configuration){ }

//new
public HelpController() : this(Startup.HttpCfg){ }

我希望这有帮助,也不会太晚;)

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....