【问题标题】:ASP.Net web API Help Page - no contentASP.Net Web API 帮助页面 - 无内容
【发布时间】:2015-11-18 18:28:31
【问题描述】:

我从 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。

我错过了什么?如有任何帮助,我将不胜感激!

【问题讨论】:

    标签: c# asp.net asp.net-web-api asp.net-web-api-helppages


    【解决方案1】:

    我可以通过在我的 Application_Start () 方法中添加 GlobalConfiguration.Configure (WebApiConfig.Register); 来解决这个问题。因为我的应用程序使用 OWIN,所以我只在 Startup.Configuration (IAppBuilder app) 中注册我的 API。

    【讨论】:

    • 谢谢!!这是我的确切问题,您的回答为我解决了!
    • 这也是我的问题。谢谢!
    • 你是天赐之物!谢谢!!
    • 太棒了!也为我工作。我也在使用 OWIN 并在 Startup 中注册。谢谢!
    • 如果这个答案有点太神秘,请参阅stackoverflow.com/questions/18921215/…
    【解决方案2】:

    你的 XMl 路径映射对了吗?

    您是否在方法中添加了摘要? /// /// 从服务器获取一些非常重要的数据。 ///

    这应该会帮助你检查过WebApi Help Page Description

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      • 2015-04-07
      • 1970-01-01
      • 2013-11-08
      相关资源
      最近更新 更多