簡體   English   中英

ASP.Net web API幫助頁面 - 沒有內容

[英]ASP.Net web API Help Page - no content

我從NuGet安裝了包,從HelpPageConfig.cs-取消注釋了該行

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

我在Properties-> Build-> XML文檔文件下設置了相同的文件,添加了一個新的Global.asax.cs文件,我在其中調用了Application_Start方法下所有區域的注冊:

protected void Application_Start(object sender, EventArgs e)
{
     AreaRegistration.RegisterAllAreas();
}

我為我的一些控制器添加了一些摘要:

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幫助頁面

介紹

在此處提供API的一般說明。

然后是一個空頁......

我嘗試調試它並在HelpController.cs中:

public ActionResult Index()
{
            ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
            return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
}

我沒有ApiDescriptions。

我錯過了什么? 我會感激任何幫助!

我能夠通過添加GlobalConfiguration.Configure (WebApiConfig.Register);來解決這個問題GlobalConfiguration.Configure (WebApiConfig.Register); 在我的Application_Start ()方法中。 因為我的應用程序使用OWIN,所以我只在Startup.Configuration (IAppBuilder app)注冊我的API。

你有沒有把XMl Path映射到你的右邊?

您是否在方法中添加了摘要? /// ///從服務器獲取一些非常重要的數據。 ///

這應該有助於您檢查WebApi幫助頁面描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM