我有一些非常奇怪的事情。我有2个控制器。 UploadController
和AccountController
。 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]
,但我只想尝试连接。
您应该在HttpGet
属性中指定路由模板:
[HttpGet("{id}")]
public async Task<ActionResult> Get(string id)
{
// ...
}