我有路由问题,因为我创建了“BaseController”。我只使用 4 个方法名称 GET、POST、PUT、DELETE,从前端进行最简单的调用。所以,当我有这个控制器时: [RoutePrefix("api/Router")]public class RouterController : WifiBaseController{ UnitOfWork unitOfWork = new UnitOfWork(); [JwtAuthentication] [HttpGet] [Route("")] public List<RouterDTO> Get() { List<router> routerx = unitOfWork.RouterRepository.Get(r => r.IsDeleted == false).ToList(); List<RouterDTO> routerDTO = Mapper.Map<List<RouterDTO>>(routerx); foreach (var router in routerDTO.Where(x => x.Password != "")) { router.Password = null; } return routerDTO; } [HttpGet] [JwtAuthentication] [Route("{latitude}/{longitude}")] public List<RouterDTO> Get(double latitude, double longitude) { List<RouterDTO> routersDTO = new List<RouterDTO>(); List<router> routers = new List<router>(); var myLocation = GPSCalculation.CreatePoint(latitude, longitude); routers = unitOfWork.RouterRepository.Get(x => x.Location.Location.Distance(myLocation) < 2000 && x.IsDeleted == false).ToList(); Mapper.Map(routers, routersDTO); foreach (var router in routersDTO.Where(x => x.Password != "")) { router.Password = ""; } return routersDTO; }我打了这个电话:http://localhost:50919/api/Router?latitude=46.767&longitude=23.60将首先调用它的方法......为什么?如果我评论第一个方法,API 将返回:405 Method Not Allowed(请求的资源不支持http方法'GET')
1 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
根据您在第二种方法中的路由属性:
[Route("{latitude}/{longitude}")]
这条路线的正确调用看起来应该是:
http://localhost:50919/api/Router/46.767/23.60
- 1 回答
- 0 关注
- 137 浏览
添加回答
举报
0/150
提交
取消