我有一堆控制器,并希望通过路由将它们分成两组:
config.Routes.MapHttpRoute(
"r1",
"api/v1.0/route1/{controller}/{action}/{id}",
new {id = RouteParameter.Optional}
);
config.Routes.MapHttpRoute(
"r2",
"api/v1.0/route2/{controller}/{action}/{id}",
new { id = RouteParameter.Optional }
);
我以为我可以这样做:
[RoutePrefix("api/v1.0/route1")]
public class MyController : ApiController
要使它仅在route1上运行,但我也可以通过route2命中它。
我也试过
[RoutePrefix("route1")]
public class MyController : ApiController
结果相同。如何让MyController只沿着route1走?任何帮助都会一如既往地受到高度赞赏。
答案 0 :(得分:1)
你想要
<script src="https://npmcdn.com/vue/dist/vue.js"></script>
<a href="javascript:void(0);" v-on:click="edit()" id="app">
{{message}}
</a>
然后是方法本身
[RoutePrefix("api/v1.0)]
public class MyController : ApiController
同意那些单独离开[Route("route1")]
public async Task<HttpResponseMessage> RouteOne(object params)
{
...
}
[Route("route2")]
public async Task<HttpResponseMessage> RouteTwo(object params)
{
...
}
的评论者。应该是这样的:
MapHttpRoute