我已经为Web Api 2安装了正确的包
Install-Package Microsoft.AspNet.WebApi.HelpPage -Pre
但是帮助区域没有映射,并返回404(Web Api工作正常).我正在使用Microsoft.Owin.Host.SystemWeb作为主机.以下是我的启动代码.
public class Startup { public void Configuration(IAppBuilder app) { //required for MVC areas new HttpConfiguration() doesn't work with MVC var config = GlobalConfiguration.Configuration; AreaRegistration.RegisterAllAreas(); WepApiStartup.Configure(config); app.UseWebApi(config); } }
解决方法
GlobalConfiguration.Configuration是特定于Web主机的HttpConfiguraiton,它只能用于Web主机场景.使用它与OWIN主机会导致意外的问题.
请改用以下代码:
public class Startup { public static HttpConfiguration HttpConfiguration { get; private set; } public void Configuration(IAppBuilder app) { HttpConfiguration = new HttpConfiguration(); AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(HttpConfiguration); app.UseWebApi(HttpConfiguration); } }
使用Startup.HttpConfiguration替换所有GlobalConfiguration.Configuration,包括帮助页面文件.