2017-12-18 259 views
0

我有一些非常奇怪的东西。我有2个控制器。 UploadControllerAccountController。 Theye都在工作,现在当我尝试AccountController时,它会给出404错误。ik不明白。.Net Core 2.0 Web API控制器无法正常工作并正在运行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],但我只是想尝试连接。

+0

你使用哪种网址为呼叫控制器行动? – CodeFuller

+0

我使用这个URL:http:// localhost:50331/api/account/{{ID}} – apero

+0

你错过了账号和id之间的斜线,不是吗?该网址应该是像http:// localhost:50331/api/account/SomeId – CodeFuller

回答

1

你应该HttpGet属性指定路径模板:

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

哦,你是最好的人!现在我还有一个错误需要解决:D – apero

相关问题