apero
apero

Reputation: 1154

.Net Core 2.0 Web API controller not working and getting 404

I have something very very strange. I have 2 controllers. UploadController and AccountController. Theye were both working, and now when I try the AccountController it give error 404. ik don't get it.

This is how my AccountController looks like:

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);
    }......

Do I miss something here? I know I comentet out the [Authorize], but i just wanted to try to connect.

Upvotes: 0

Views: 3234

Answers (1)

CodeFuller
CodeFuller

Reputation: 31282

You should specify route template in HttpGet attribute:

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

Upvotes: 1

Related Questions