【发布时间】:2017-09-16 05:43:37
【问题描述】:
[HttpGet]
[Route("api/CheckMainVerified/{mainid}", Name = "CheckMainVerified")]
public IHttpActionResult CheckIfVerified(int mainid)
所以我发现属性上有一个Name属性
但我不知道如何访问它。
我希望能够检查是否有人可以访问带有令牌等的数据库表中存储的 api。所以我不在乎它是否是以下任何一种
api/CheckMainVerified/
CheckMainVerified
我无法通过 {whatever} 了解它
因为这个 api/CheckMainVerified/{mainid} 最终会出现在示例的传入 URL 中
.../api/CheckMainVerified/32342343
由于 URL 可能有如此多的变体,因此检查所有带有值的参数将是一场噩梦
/api/books/45/outlets/3/sections/abc/location/9
所以理想情况下,我希望能够只查看“名称”,然后将“CheckMainVerified”放在我查找的数据库表中。
【问题讨论】:
-
不确定,使用名称是实现您想要实现的目标的好方法。
-
这不是 Name 参数的使用方式。在这里阅读docs.microsoft.com/en-us/aspnet/web-api/overview/…
-
我知道这不是它在 Url.link 中使用的方式,但很遗憾我无法访问它docs.microsoft.com/en-us/aspnet/web-api/overview/…
-
不是参数,Name是属性
To specify the route name, set the Name property on the attribute上的属性
标签: c# asp.net-web-api asp.net-web-api2 asp.net-web-api-routing