c# - ASP.Net Web API 帮助页面 - 无内容

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

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

相关文章:

c# - 在特定时间间隔后执行任务的最佳做法是什么?

c# - 提交时下拉值重置为初始值

asp.net - asp.net MVC3 中自动生成的表单

api - 在 mvc Web API Controller 中按字符串 id 搜索

c# - C# 中的正则表达式电子邮件验证器中的问题

c# - 需要改进的线程锁定建议

c# - Owin 中间件 VS WebAPI DelegatingHandler

json - Ember 数据 : Using "links" on JSON payload for hasMany relationships

c# - MVC 3 View 中的 2 个模型

javascript - 获取Controller的返回值给javascript