无法在webapi

时间:2017-08-30 01:58:35

标签: asp.net-web-api

我有一个带有两个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;
            }

        }

0 个答案:

没有答案