MVC区域路由解析 [英] MVC area route resolution

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

问题描述

如果您的解决方案中有区域,请使用MVC3/4,它将尝试解决区域和根级别控制器的顺序是什么?

Using MVC3/4 if you have area's in your solution, what is the order that it will try and resolve the areas and root level controllers?

例如:

是否先按字母顺序尝试根级路由,然后再尝试区域级路由?

Does it first try the root level routes and then the area level routes in alphabetical order?

还是先按字母顺序检查区域级别的路由,然后再检查根级别?

Or does it first check the area level routes in alphabetical order and then the root level?

谢谢

推荐答案

MVC解析器首先针对特定区域路由,然后是根级别路由.这是因为默认情况下,您在Global.asax中具有下一个代码:

MVC resolvers area specific routes first and then root level routes. This is because by default you have next code in Global.asax:

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas(); //1. registers areas

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes); //2. only after that register root routes
    }

我还没有尝试过,但是如果您想更改此行为,则可以尝试在项目中交换这些代码行.

I have not tried it but if you would like to change this behavior you may try to swap these code lines in you project.

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

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