.Net Core 2.0 Web API控制器无法正常工作并获得404

时间:2017-12-18 14:07:20

标签: api asp.net-core-2.0 asp.net-core-webapi

我有一些非常奇怪的事情。我有2个控制器。 UploadControllerAccountController。 Theye都在工作,现在当我尝试AccountController时,它会给出错误404.Ik不会得到它。

这就是AccountController的样子:

namespace CoreAngular.Controllers
{
    //[Authorize]
    [Produces("application/json")]
    [Route("api/account")]
    public class AccountController : Controller
    {
        private IRepository repository;

    public AccountController(IDatabaseClient<DocumentClient> client) 
        : this ( new UserRepository(client))
    {
    }

    public AccountController(IRepository repository)
    {
        this.repository = repository;
    }

    [HttpGet]
    public async Task<ActionResult> Get(string id)
    {
        var start = DateTime.Now.TimeOfDay;
        if (string.IsNullOrEmpty(id))
        {
            return BadRequest();
        }

        var user =  await repository.GetAsync(id);
        if (user == null)
        {
            return NotFound();
        }
        var userDTO = new UserGetDTO()
        {
            image = Convert.ToBase64String(user.image.image),
            id = user.id,
            time = DateTime.Now.Subtract(start).Millisecond
        };
        return Ok(userDTO);
    }......

我在这里想念一下吗?我知道我告诉了[Authorize],但我只想尝试连接。

1 个答案:

答案 0 :(得分:1)

您应该在HttpGet属性中指定路线模板:

[HttpGet("{id}")]
public async Task<ActionResult> Get(string id)
{
    // ...
}