未找到与请求URI匹配的HTTP资源

Kgn*_*web 5 asp.net-web-api postman

我检查了一些链接,以了解错误的原因,但没有解决我的问题.

我试图从Postman访问WebAPi操作,但得到以下错误.

"message":"找不到与请求URI匹配的HTTP资源' http:// localhost:50684/api/albums/history '.",
"messageDetail":"找不到与名为'album'的控制器匹配的类型".

我的API.

[Authorize]
public class AlbumsController : ApiController
{

   [HttpGet]
   [Route("api/album/history/")]
   public BaseTO GetHistory(string type,int id)
   {  
      //api stuff
   }
 }
Run Code Online (Sandbox Code Playgroud)

我试过了 api/album/history/{anything}

在接到Postman的电话时,我正在路过: -

  • 授权令牌
  • 类型
  • ID

任何帮助/建议高度赞赏.谢谢

Dev*_*per 6

你在api配置中启用了属性路由吗? config.MapHttpAttributeRoutes();

使用当前路径,您应该通过查询字符串命中它http://localhost:50684/api/albums/history?type=test&id=1并使用[FromUri]

[HttpGet]
   [Route("api/albums/history/")]
   public IHttpActionResult GetHistory([FromUri]string type,[FromUri]int id)
   {  
      //api stuff
   }
Run Code Online (Sandbox Code Playgroud)

或通过路线参数点击api - http://localhost:50684/api/albums/history/test/1

[HttpGet]
   [Route("api/albums/history/{type}/{id}")]
   public IHttpActionResult GetHistory(string type,int id)
   {  
      //api stuff
   }
Run Code Online (Sandbox Code Playgroud)