在WebApi2帮助页面中启用文档



我有一个简单的webapi2项目。

我能找到的唯一信息似乎是关于旧的webapi1

如果我有,从我的控制器

/// <summary>
/// Gets a list of not very interesting information
/// </summary>
/// <returns>The list</returns>
[ResponseType(typeof(ExampleModel))]
public IHttpActionResult Get()
{
var data = new List<ExampleModel>()
{
new ExampleModel()
{
Date = DateTime.Now,
Name = "Tom"
},
new ExampleModel()
{
Date = DateTime.Now.AddDays(-20),
Name = "Bob"
}
};

为什么当我尝试浏览到帮助页面时没有显示任何信息。我被告知没有可用的文件。

有没有一个神奇的开关可以打开这些数据的自动填充?

如果你提到显示xml注释,那么你可以在这里找到我的答案:

使用控制器上的Xml注释的ASP.NET Web API帮助页文档

请确保在区域/HelpPage/App_Start/HelpPageConfig.cs 中取消注释此代码

// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));

还要确保xml文件位于App_Data中,而不是项目属性中默认的bin中

最新更新