MVC 2 区域注册路由顺序 [英] MVC 2 AreaRegistration Routes Order

查看:23
本文介绍了MVC 2 区域注册路由顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在 MVC 2 Preview 2 中,AreaRegistration 以任意顺序加载每个区域的路由.有什么好方法可以先得到一个吗?

I noticed that in MVC 2 Preview 2, AreaRegistration is loading the routes for each area in an arbitrary order. Is there a good way to get one before the other?

例如,我有两个区域 - 站点"和管理员".两者都有一个博客"控制器.

For example, I have two areas - "Site" and "Admin". Both have a "Blog" controller.

我想要以下内容:

/admin/ --> go to Admin's Blog controller
/       --> go to Site's Blog controller. 

问题是它首先加载站点的路由,所以它匹配 {controller}/{action}/{id} 而不是 admin/{controller}/{action}/{id} 当我转到网址/admin/"时.然后我收到 404,因为站点"区域中没有管理控制器.

The problem is that it is loading the site's route first, so it is matching {controller}/{action}/{id} instead of admin/{controller}/{action}/{id} when I go to the url "/admin/". I then get a 404, because there is no Admin controller in the "Site" area.

两个区域都默认为博客"控制器.我意识到我可以简单地将 site/{controller}/... 作为 url,但如果可能的话,我宁愿将它放在根目录中.我也尝试在全局 RegisterRoutes 函数中保留默认路由,但是,它不会发送到站点"区域.

Both areas default to the "Blog" controller. I realize I could simply put site/{controller}/... as the url, but I would rather have it at the root if possible. I also tried keeping the default route in the global RegisterRoutes function, however, it is then not sent to the "Sites" area.

提前致谢!

推荐答案

目前无法订购区域.但是,我认为尝试使每个区域尽可能独立于其他区域是有意义的,因此顺序无关紧要.

Currently it's not possible to order areas. However, I think it makes sense to try and make each area as independent from other areas as possible so the order doesn't matter.

例如,不是使用默认的 {controller}/{action}/{id} 路由,而是可以将其替换为每个控制器的特定路由.或者向该默认路由添加约束.

For example, instead of having the default {controller}/{action}/{id} route, maybe replace that with specific routes for each controller. Or add a constraint to that default route.

我们正在考虑允许订购的选项,但我们不想使该功能过于复杂.

We are mulling over options to allow ordering, but we don't want to overcomplicate the feature.

这篇关于MVC 2 区域注册路由顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆