显示出两个版本的每个方法的Web API帮助页面两个、版本、页面、方法

2023-09-03 17:43:45 作者:风吹不散你我

如何才能避免显示我的方法的两个版本的帮助页面?

How can I avoid the Help page showing both versions of my method?

正如你所看到的,我已经设置了一个自定义路由 / API /属性/搜索/ {finnId} ,但我不想要的使用查询参数显示在帮助页面。要解决这个办法吗?我使用的ASP.NET 2012年秋季BUILD preVIEW内置的帮助页面。

As you can see, I've set up a custom route for /api/property/search/{finnId}, but I don't want the one using query parameters to show up in the Help page. Any way to get around this? I'm using the built in Help page from the ASP.NET Fall 2012 BUILD preview.

顺便说一句,不用担心的是,它说 POST ,因为我已经切换到 GET ,但我得到了相同的结果。

Btw, don't worry about the fact that it says POST, I've since switched it to GET, but I get the same results.

推荐答案

如果你只是寻找隐藏这条路线在帮助页面,并没有真正禁用它的应用程序,你总是可以调整显示模板中的逻辑。

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.

您可以修改 ... \ DisplayTemplates \ ApiGroup.cshtml 通过增加逻辑来看看每个API,那将被渲染,并决定是否要基于它包含文件在URL中的查询字符串的presence。

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.