Web API Help page showing two versions of every method

核能气质少年 提交于 2019-12-06 01:30:21

If you're simply looking to hide this route in the Help page and not actually disable it in the app, you could always tweak the logic in the display template.

You could modify the "...\DisplayTemplates\ApiGroup.cshtml" file by adding logic to look at each api that's going to be rendered and decide whether or not you want to include it based on the presence of a query string in the URL.

Still, the important thing to note is that this does not disable the route. You're just hiding it on this Help page. If you want to disable the route, I think you'll need to define your own custom routes.

As there are different combinations of route request for Api, help page by default shows all combination.If we just want to hide the display on the UI, we could remove the items from collection in HelpController.cs

//helpcontroller.cs 
        public ActionResult Index()
        {
            ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
            //return View(Configuration.Services.GetApiExplorer().ApiDescriptions); 
            var apiExplorer = Configuration.Services.GetApiExplorer();
            for (int i = apiExplorer.ApiDescriptions.Count - 1; i >= 0; i--)
            {
                if (apiExplorer.ApiDescriptions[i].RelativePath.Contains("?")) { apiExplorer.ApiDescriptions.RemoveAt(i); }
            }
            return View(apiExplorer.ApiDescriptions);
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!