我有一个带有两个HttpGet的webapi控制器。我定义了如下所示的路线。 当我使用下面的链接调用方法时,我的断点不会被击中。
http://localhost:49869/Api/Articles/SearchArticles/News
http://localhost:49869/Api/Articles/DefaultArticles/News
此链接不正确吗?
[Route("api/[controller]")]
public class ArticlesController : ApiController
{
// GET api/Articles/News
[HttpGet]
[Route("SearchArticles/{category}")]
public IEnumerable<ArticlesDto> Get(string category)
{
IEnumerable<ArticlesDto> articlesByCategory = null;
try
{
if (category == null)
{
}
articlesByCategory = _articlesrepository.Find(category);
}
catch(Exception ex)
{
}
return articlesByCategory;
}
// Get api/Articles/News
// Pull default articles by category data
[HttpGet]
[Route("DefaultArticles/{category}")]
public IEnumerable<ArticlesDto> GetDefault(string category)
{
IEnumerable<ArticlesDto> defaultArticlesByCategory = null;
try
{
if (category == null)
{
}
defaultArticlesByCategory = _articlesrepository.FindDefault(category);
}
catch (Exception ex)
{
//return BadRequest(ex.Message);
}
return defaultArticlesByCategory;
}
}