Asp.net web api 属性路由压缩路由
我正在使用WebApi的nuget包。下面是我的两个GET方法和route属性,用于list和一个特定项:Asp.net web api 属性路由压缩路由,asp.net-web-api,attributerouting,asp.net-mvc-apiexplorer,Asp.net Web Api,Attributerouting,Asp.net Mvc Apiexplorer,我正在使用WebApi的nuget包。下面是我的两个GET方法和route属性,用于list和一个特定项: [GET("api/products/{tenantid}/{channelid}?{skip=0}&{take=20}&{status=1}")] public IEnumerable<Product> Get(short tenantId, byte channelId, int status, int skip, int take) [GET("api/
[GET("api/products/{tenantid}/{channelid}?{skip=0}&{take=20}&{status=1}")]
public IEnumerable<Product> Get(short tenantId, byte channelId, int status, int skip, int take)
[GET("api/products/{tenantid}/{channelid}/{id}")]
public Story Get(short tenantId, byte channelId, long id)
即使“id”不是第一个GET方法的参数。如何消除结尾带有“?id={id}”的中间URI?我想我需要某种约束,但我无法从文档站点上找到它
现在,对于路由“a”,ApiExplorer检查可以到达哪些操作,并注意到对于控制器“Products”和操作“Get”,有两个可以访问的操作,它还会尝试查看有多少参数来自路由路径本身,如果操作上有任何参数不是来自路由路径,它会假定它来自查询字符串…因此您会看到“?id={id}”。希望这有帮助。解决了它。我甚至没有想过要更改方法名。当切换到备用路由技术时,我应该认识到方法名不是路由约定的一部分。
GET api/products/{tenantid}/{channelid}?status={status}&skip={skip}&take={take}
GET api/products/{tenantid}/{channelid}?id={id}
GET api/products/{tenantid}/{channelid}/{id}