ASP.NET MVC 2 Beta版的单项目区注册获得HTTP 404 [英] ASP.NET MVC 2 Beta single-project Area registration getting HTTP 404

查看:74
本文介绍了ASP.NET MVC 2 Beta版的单项目区注册获得HTTP 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让ASP.NET MVC 2单项目区登记工作。试着用preVIEW 2和现在的Beta版,没有运气。我用添加区域对话框创建NewsModule区域。创建一个NewsModuleController里面并为它索引视图。

I'm trying to get ASP.NET MVC 2 single-project area registration to work. Tried with Preview 2 and now with Beta version with no luck. I used the "Add area" dialog to create a "NewsModule" area. Created a NewsModuleController inside it and an Index view for it.

有关这方面的路线注册是这样的:

The route registration for this Area looks like this:


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

我添加了AreaRegistration.RegisterAllAreas();打电话给我的Global.asax。
访问的http://本地主机/ mymvcproj / NewsModule 得到一个HTTP 404错误

I added the AreaRegistration.RegisterAllAreas(); call to my Global.asax. Accessing http://localhost/mymvcproj/NewsModule gets a HTTP 404 error.

使用菲尔哈克的路线调试器,我可以证实,该航线被正确映射并以此URL逮住,但是,它似乎是一个框架不能够找到区域中的文件,也许?

Using Phil Haack's route debugger, I could confirm that the route is being correctly mapped and catched by this URL, however, it seems like the framework is not being able to locate the Area files, maybe?

任何人都可以帮忙吗?

谢谢,
费利佩

Thanks, Felipe

推荐答案

问题解决了。这里是我做过什么来解决:

Problem solved. Here is what I did to solve:

AreaRegistration.cs文件:

AreaRegistration.cs file:


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

重要提示:添加.Areas。命名空间(Namespace.Areas.ControllerName)。

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

的Global.asax.cs:

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);
}

这篇关于ASP.NET MVC 2 Beta版的单项目区注册获得HTTP 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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