我已经添加了帮助页面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){ }
我希望这有帮助,也不会太晚;)