ASP.NET MVC 2 Beta single-project Area registration getting HTTP 404

假装没事ソ 提交于 2019-12-06 15:47:35

Problem solved. Here is what I did to solve:

AreaRegistration.cs file:

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

IMPORTANT: Add the ".Areas." to the namespace (Namespace.Areas.ControllerName).

Global.asax.cs:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    // must be called RIGHT AFTER IgnoreRoute()
    AreaRegistration.RegisterAllAreas();

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

    //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}

Try removing "area = "NewsModule" from the route registration in the Area/NewsModule folder. So it appears like,

context.MapRoute(
                "NewsModule_default",
                "NewsModule/{action}/{id}",
                new { action = "Index", id = "", controller = "NewsModule"}
            );

Here is my Account Area Routes Registration,

Location /Areas/Account/

public class AccountAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get { return "Account"; }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Account_default",
                "Account/{controller}/{action}/{id}",
                new { controller = "", action = "", id = "" }
            );
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!