asp.net mvc的区域默认页面

问题描述:

我有一个MVC 2个网站,面积,假设该地区的名字是{}管理员

I have a MVC 2 site with an area, let's say the area name is {Admin}

该地区和该网站正常工作。

The areas and the site works fine.

我所试图做的是有不同的默认页的区域。

What I am trying to do is to have different default page for the area.

当我打电话的http:// webSiteName 没有问题的作品

When I am calling http://webSiteName works with no problem

的http:// webSiteName /管理员我收到错误

资源无法找到

我尝试过了,从http://*.com/questions/2314524/asp-net-mvc-2-rc-2-returns-area-specific-controller-when-no-area-specified
但没有运气。

I tried it out the solutions from http://*.com/questions/2314524/asp-net-mvc-2-rc-2-returns-area-specific-controller-when-no-area-specified but with no luck.

我也试过

routes.MapRoute(
                 "Admin",                                         
                 "{controller}/{action}/{id}",                               
                 new { controller = "AdminHome", action = "index" },
                 new[] { "Web.Areas.Admin.Controllers" }
                 );

routes.MapRoute(
                 "Admin",                                      
                 "Admin",                              
                 new { controller = "AdminHome", action = "index" },   
                 new string[] { "Web.Areas.Admin.Controllers" }
                 );

但我仍然得到资源无法找到。

我在做什么错了?

试试这个。请确保它会在 /Areas/Admin/AdminAreaRegistration.cs 时,您的区域被命名为管理​​

Try this. Make sure it will be in /Areas/Admin/AdminAreaRegistration.cs when your Area is named Admin.

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { controller = "AdminHome",action = "Index", id = "" }
        );
    }

您不必添加任何东西到你的的Global.asax

You don't have to add anything to your Global.asax.