加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-web-api – 在WebApi2帮助页面中启用文档

发布时间:2020-12-15 22:18:54 所属栏目:asp.Net 来源:网络整理
导读:我有一个简单的webapi2项目. 我似乎发现自己的唯一信息是指较旧的webapi1 如果我有我的控制器 /// summary /// Gets a list of not very interesting information /// /summary /// returnsThe list/returns [ResponseType(typeof(ExampleModel))] public IH
我有一个简单的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评论,那么你可以在这里找到我的答案:

ASP.NET Web API Help Page documentation using Xml comments on controllers

请务必在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中,它默认位于项目属性中

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读