我正在开发一个.net核心Web API项目。我有两个控制器,它们具有相同的结构。但是其中一个正在工作,但另一个正在给出404错误。我的代码片段如下:
//mvc routing in the Configure method in the startup class
app.UseMvc(routes =>
{
routes.MapRoute(name: "default", template: "api/{controller}/{action}/{id?}");
});
我的控制器是:
[Route("api/user")]
public class ManagerController : Controller
{
//this is working
[HttpGet("myitems/{id}")]
public IActionResult GetItems(String id){...}
}
../api/user/myitems/123 is working
[Route("api/price")]
public class HistController : Controller
{
//this is not working !!!
[HttpGet("item/{id}")]
private IActionResult GetItemPrice(String id) {...}
}
../api/price/item/123 is not working! (404 error)
你能建议一个解决方案吗?
答案 0 :(得分:0)
GetItemPrice
方法为private
。它必须是public
。