【发布时间】:2017-05-16 07:04:25
【问题描述】:
我在asp.net core中创建了一个Web Api这个Api的内容:
[Route("api/[controller]")]
public class BlogController : Controller
{
public IContext _context { get; set; }
public BlogController(IContext ctx)
{
_context = ctx;
}
[HttpGet]
[Route("api/Blog/GetAllBlog")]
public List<Blog> GetAllBlog()
{
return _context.Blogs.ToList();
}
}
据我所知,在 Asp.net Core(WebApi 模板)中,我们不需要像注册路由这样的配置,而在 Asp.net Mvc 5.3 及更早版本中我们需要。
所以当我尝试通过浏览器或邮递员调用GetAllBlog 时,通过此网址http://localhost:14742/api/Blog/GetAllBlog,它让我404 error,有什么问题?
【问题讨论】:
标签: asp.net-web-api asp.net-core