2017-01-30 80 views
0

我正在開發一個.net核心web API項目。我有兩個控制器,它們具有相同的結構。然而,其中一個正在工作,但另一個正在給404錯誤。我的代碼片段如下:net net web api:一個控制器正在工作,但另一個不是

 //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) 

能否請您提出一個解決辦法?

+1

爲什麼這種方法'私人'?將其更改爲'public IActionResult GetItemPrice' – Developer

+0

謝謝@Developer。我試圖解決整個週末的問題! – tempx

回答

0

GetItemPrice方法是private。它需要是public

相關問題