在区域Areas下共2个区域
User,Course在AreaRegistration中配置都是,只是名字不同而已 context.MapRoute(
                "Course_default",
                "{controller}/{action}/{id}",
                new { action = "List", id = UrlParameter.Optional });
这样的话,如果只有一个区域页面访问地址可以是http://localhost:12716/User/Login和http://localhost:12716/Course/List/2但是两个并存的话我目前知道的是只能在  "{controller}/{action}/{id}", 加前缀,如"Course/{controller}/{action}/{id}"或"User/{controller}/{action}/{id}"这样我又觉得URL有点长,而且也没必要,不知道各位前辈有没什么解决办法可以找个问题,URL对我来说简单,明了,能找对应地址就可以了

解决方案 »

  1.   

    area的url就是这个结构,不长area/controller/action/id
      

  2.   

    area/controller/action/id 这还不长?
    能不能只有/controller/action/id呢?
      

  3.   

    你的user和source不是controller么
      

  4.   

    区域名 和 controller都是这个名字
      

  5.   

    context.MapRoute(
                    "Course_default",
                    "Course/{action}/{id}",
                    new { controller = "要访问的controller名", action = "Index", id = UrlParameter.Optional }
                );
      

  6.   

    ASP.NET Mvc  Areas
      

  7.   

    貌似不加前缀,control/action 不是会冲突? 调用哪个区域的?
      

  8.   

    还是用了如梦大师兄的解决方案
    我把其他区域的默认路由都改了,如果一旦有默认路由匹配了,那么就会执行默认路由,所以我们自己配置的也就失效了,所以解决方案取消默认路由
    MSDN给出的解决方案我找到的(有可能是我没找到)办法是这些自己配置的路由写在默认之前,由于我这里用的是区域,所以我也不知道各个路由怎么组合到一起,按照我想要的顺序来写。比较可悲,具体的我在好好学学,如有进展再跟大伙分享。
    感谢楼上所有朋友
    晚点结贴,希望可以给油同样困惑的朋友一点提醒和帮助。
      

  9.   


    不长,只有/controller/action/id,那就不要用area
      

  10.   

    其实大可不必那么麻烦,不需要用反射来做
    比如注册2个区域Profile和Blog,将会有两个这样的文件
    ProfileAreaRegistration.cs
    BlogAreaRegistration.cs
    直接在这里面做文章就OK了
    public override void RegisterArea(AreaRegistrationContext context)
            {
                context.MapRoute(
                    "Profile_default",
                    "Profile/{controller}/{action}/{id}",
                     new { controller = "Profile", action = "Index", id = UrlParameter.Optional, pageIndex = UrlParameter.Optional },
                    new string[] { "MVCTest.Areas.Profile.Controllers" }
                );
            }在 BlogAreaRegistration.cs里面也一样的做法
    public override void RegisterArea(AreaRegistrationContext context)
            {
                context.MapRoute(
                    "Profile_default",
                    "Blog/{controller}/{action}/{id}",
                     new { controller = "Blog", action = "Index", id = UrlParameter.Optional, pageIndex = UrlParameter.Optional },
                    new string[] { "MVCTest.Areas.Blog.Controllers" }
                );        }
    这样URL访问形如:
    Profile/Test/Index就访问Profile
    Blog/Test/Index就访问BlogLZ可能是忘记写 new string[] { "MVCTest.Areas.Profile.Controllers" }命名空间了
    如梦给出的页面,也是添加命名空间来实现,为什么不直接在这里面实现?
      

  11.   

    哦 错了,有个{controll} 呵呵 sorry
      

  12.   

    那个示例我下载看了
    比如他的controller = "Blog", 把控制器名称固定了,那这样不是很不灵活了,如果要在Controllers文件夹下面写其他名字的controller怎么办?