我在Account控制器中有一个方法(使用RoutePrefix(“api / Account”),我想回复api / users而不是api / account,所以我使用'〜'来覆盖它:
[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'
无论如何这应该有用,但不是出于某种原因,任何人都可以提出原因吗?
答案 0 :(得分:4)
路线需要......
[Route("~/api/users/{name:alpha}/exists")]