2014-02-23 118 views
1

我有一个帐户控制器中的方法(使用RoutePrefix(“API /帐户”),我想响应API /用户而不是API /帐户,所以我用'〜'来覆盖它:Webapi 2属性路由不起作用

[HttpGet] 
[AllowAnonymous] 
[Route("~api/users/{name:alpha}/exists")] 
public async Task<IHttpActionResult> UserExists(string name) 
{ 
    var res = await UserManager.FindByNameAsync(name); 
    if (res != null) 
     return Ok(); 
     return BadRequest(); 
} 


So when I try it out I get the response: 
No HTTP resource was found that matches the request URI 'http://localhost:21975/api/users/johndoe/exists' 

通过一切手段,这应该工作,但它不是出于某种原因,任何人都可以说明为什么

回答

4

路线必须...

[Route("~/api/users/{name:alpha}/exists")] 
+0

正要张贴?这个,你错过了相对根后的第一个'/'。 – Xenolightning