zoukankan      html  css  js  c++  java
  • C# HelpPage 接口文档配置

    1、打开项目路径如下的类文件:

    1.1、找类方法 Register 下的 config.SetDocumentationProvider 并取消注释,修改 ~/App_Data/XmlDocument.xml  为你自己的路径,
    config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data")))
     1.2、打开 XmlDocumentationProvider 类文件

     1.2.1、找到类中找到变量 _documentNavigator,修改如下所示
     //private XPathNavigator _documentNavigator;
       private List<XPathNavigator> _documentNavigators = new List<XPathNavigator>();

    1.2.2、找到类的方法 XmlDocumentationProvider ,修改如下:

     public XmlDocumentationProvider(string documentPath)
            {
                if (documentPath == null)
                {
                    throw new ArgumentNullException("documentPath");
                }
                //注释这两行
                //XPathDocument xpath = new XPathDocument(documentPath);
                //_documentNavigator = xpath.CreateNavigator();
                //新增如下
                DirectoryInfo theFolder = new DirectoryInfo(documentPath);
                foreach (var item in theFolder.GetFiles("*.xml"))
                {
                    XPathDocument xpath = new XPathDocument(Path.Combine(documentPath, item.Name));
                    _documentNavigators.Add(xpath.CreateNavigator());
                }
            }
    1.2.3、在 XmlDocumentationProvider 方法之后添如下方法
     private XPathNavigator SelectSingleNode(string selectExpression) {
                foreach (var navigator in _documentNavigators) {
                    var propertyNode = navigator.SelectSingleNode(selectExpression);
                    if (propertyNode != null)
                        return propertyNode;
                }
                return null;
            }
     1.2.4、修改 类中所有引用为 _documentNavigator.SelectSingleNode 的地方,修改成 新增的方法 SelectSingleNode

    注意:新建的控制器必须继承  ApiController  否则界面不会展示控制器接口!

     2、添加接口详情测试按钮

    2.1、通过Nuget包管理添加 webapitestclient 添加完成后找到这个 Areas->HelpPage->Views->Help 路径下的  Api.cshtml 文件,修改如下

    @using System.Web.Http
    @using API.Areas.HelpPage.Models
    @model HelpPageApiModel
    
    @*解析html*@
    @section Scripts {
        @Html.DisplayForModel("TestClientDialogs")
        @Html.DisplayForModel("TestClientReferences")
    }
    
    @{
        var description = Model.ApiDescription;
        ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath;
    }
    
    <link type="text/css" href="~/Areas/HelpPage/HelpPage.css" rel="stylesheet" />
    <div id="body" class="help-page">
        <section class="featured">
            <div class="content-wrapper">
                <p>
                    @Html.ActionLink("Help Page Home", "Index")
                </p>
            </div>
        </section>
        <section class="content-wrapper main-content clear-fix">
            @Html.DisplayForModel()
        </section>
    </div>
  • 相关阅读:
    在預設設定下,SQL Server 不允許遠端連接
    windows7语言包安装失败
    使一个销售组织能够销售另一个销售组织的产品
    转:多线程六种多线程方法解决UI线程阻塞
    转:BeginInvoke和EndInvoke方法 (原网址:http://www.cnblogs.com/nokiaguy/archive/2008/07/13/1241817.html)
    员工客户的统驭科目不能更改?
    公司间采购的退货(有序列号)
    排程 经典图示
    取消凭证分解 (取消公司下的多个利润中心)
    查找已删除的交货单信息
  • 原文地址:https://www.cnblogs.com/miskis/p/7551886.html
Copyright © 2011-2022 走看看