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

问题描述 投票:0回答:1

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

这就是我的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],但我只想尝试连接。

api asp.net-core-2.0 asp.net-core-webapi
1个回答
1
投票

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

[HttpGet("{id}")]
public async Task<ActionResult> Get(string id)
{
    // ...
}
© www.soinside.com 2019 - 2024. All rights reserved.