global.asax文件中的区域路由

时间:2012-08-24 15:45:46

标签: asp.net-mvc

在我的mvc应用程序中,我有Admin区域,并且在区域外有默认控制器。我想在global.asax文件中定义路由,以便默认和管理。 比如用户输入:{http:// localhost /} - >打开默认路线 如果用户输入:{http:// localhost / Admin /} - >打开管理路线

如果有人有想法处理这个问题,请建议。

1 个答案:

答案 0 :(得分:0)

创建管理区域注册文件。如:

public class AdminAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Admin";
        }
    }

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

然后从Global.asax中调用它

        AreaRegistration.RegisterAllAreas();
相关问题