.NET MVC 自定义路由
我想知道是否可以创建一个比控制器更高级别的路由映射。典型的路由将包括“/controller/action/id”。我正在寻找类似“section/controller/action/id”或“controller/section/action/id”的内容。我该怎么做?
I was wondering if I could create a routing map with one more higher level than the controller. The typical routing would include "/controller/action/id". What I am looking for is something like "section/controller/action/id" or "controller/section/action/id". How can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没问题。只需创建一个路由,其 URL 例如
path/to/my/application/{controller}/{action}/{id}
...并像往常一样提供默认控制器和操作。
一个具体的例子是
这将映射例如以下 URL:
但请注意,如果您还有默认路由,例如如下所示:
...那么管理路由中的控制器操作方法也可以访问通过这条路线。使用URL路由调试器来确定。
No problem. Just create a route the URL of which is, for example
path/to/my/application/{controller}/{action}/{id}
...and supply a default controller and action as usual.
A concrete example of this is
This will map, for example, the following URLs:
Note, though, that if you also have a default route, for example like this:
...then controller action methods in the Admin routing may also be accessible via this route. Use the URL Routing Debugger to find out for sure.