【发布时间】:2018-12-29 20:27:28
【问题描述】:
我已经建立了一个非常简单的 ASP.NET Core 2.1 Web API 项目,并创建了一个使用 EF Core 获取实体的简单控制器。
问题是当尝试使用 Postman 访问 GetEntities 方法时,响应是 404 错误。我在以下 URL 上使用了 HTTP GET 方法。
https://localhost:44311/api/entities
响应正文包含消息<pre>Cannot GET /api/entities</pre>。
为什么 Postman 收到此路由的 404 错误?
EntitiesController.cs
namespace MyProject.Controllers
{
[Route("api/controller")]
public class EntitiesController : Controller
{
private readonly ApplicationDbContext dbContext;
public EntitiesController(ApplicationDbContext _dbContext)
{
this.dbContext = _dbContext;
}
[HttpGet]
public IActionResult GetEntities()
{
var result = dbContext.Entities.ToListAsync();
return Ok(result);
}
}
}
【问题讨论】:
标签: c# http asp.net-core postman