我从 NuGet 安装包,取消注释 HelpPageConfig.cs-
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
我在 Properties->Build->XML documentation file 下设置了相同的文件, 添加了一个新的 Global.asax.cs 文件,我在其中调用了 Application_Start 方法下所有区域的注册:
protected void Application_Start(object sender, EventArgs e)
{
AreaRegistration.RegisterAllAreas();
}
我为我的一些 Controller 添加了一些摘要:
public class IncidentsController : ApiController
{
/// <summary>
/// this is the summary
/// </summary>
/// <param name="incidentId">this is incidentId</param>
/// <returns>it returns something</returns>
[Route("{incidentId}")]
[HttpGet]
public object GetIncidentById(int incidentId)
{
return Incidents.SingleOrDefault(i => i.id == incidentId);
}
}
当我运行网页并转到“/help”时,我唯一看到的是
ASP.NET Web API Help Page
Introduction
Provide a general description of your APIs here.
然后是一个空白页...
我尝试调试它并在 HelpController.cs 中:
public ActionResult Index()
{
ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
}
我没有得到 ApiDescriptions。
我错过了什么?我将不胜感激!
最佳答案
我能够通过在我的 Application_Start ()
方法中添加 GlobalConfiguration.Configure (WebApiConfig.Register);
来解决这个问题。因为我的应用程序使用 OWIN,所以我只在 Startup.Configuration (IAppBuilder app)
中注册了我的 API。
关于c# - ASP.Net Web API 帮助页面 - 无内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32197432/