Asp.net-Web-Api
在 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 幫助頁面文件
請務必在 Areas/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