【发布时间】:2015-11-21 13:15:24
【问题描述】:
我正在尝试在测试 MVC 6 Web API 项目中创建通配符路由。但我不知道该怎么做。我目前在我的Controller 课程中有这个。
// GET: api/values
[HttpGet("{*anything:regex(^(.*)?$)}")]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{*anything}/{id}")]
public string Get(int id)
{
return "value";
}
如果我的Controller 中只有第一个Get(),那么它可以工作。但是,当我添加第二个Get(int id) 方法时,我会得到一个Internal Server Error。事实上,正是[HttpGet("{*anything}/{id}")] 行导致了上述第二个Get 方法的问题。
我该如何解决这个问题?
【问题讨论】:
标签: asp.net-web-api asp.net-web-api2 asp.net-core-mvc