ServiceRoute覆盖现有路由 [英] ServiceRoute overriding Existing routes
问题描述
采用MVC模式的新手,请耐心等待.
a newbee in MVC patterns, so please bear it with me.
我已经在global.asax
文件
RouteTable.Routes.Add(new ServiceRoute("rest", new WebServiceHostFactory(), typeof(ServiceName)));
这条路线现在覆盖了我现有的路线.为了更好地说明这一点,将其设置为"/rest/Controller/Action"
.但这必须是"/Controller/Action"
this route is now overriding my existing routes. to better explain this, its setting as "/rest/Controller/Action"
. but this has to be "/Controller/Action"
RouteEngine
将我的ServiceRoute
附加在动作calls
中.
RouteEngine
is appending my ServiceRoute
in Actions calls
.
如何设置确切的映射.
推荐答案
您必须使用约束,并以正确的顺序注册路由.
You have to use constraints, and register routes in the right order.
您可以获取有关以下内容的完整说明这里发生了什么.
在阅读它时,请记住MapServiceRoute方法已经消失了,注册服务的方式就是您选择的方式.
When reading it remember that the MapServiceRoute method has dissapeared, and the way to register services is what you have chosen.
您不需要实现IRouteCOnstraint.您可以只使用正则表达式.
You don't need to implement IRouteCOnstraint. You can just use a regex.
这篇关于ServiceRoute覆盖现有路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!