ASP.NET MVC 2区404 [英] ASP.NET MVC 2 Areas 404

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

问题描述

有没有人能够得到ASP.NET MVC 2的地区工作?

Has anyone been able to get the Areas in ASP.NET MVC 2 to work?

我创建了一个名为安全的新领域,并放置一个新的控制器,任命HomeController的。然后我创建了一个新的家庭/的Index.aspx视图。然而,当我浏览到的http://本地主机/ MyApp的/安全/ 的,它提供了404资源无法找到。 的http://本地主机/ MyApp的/安全/家庭给出了同样的错误。

I created a new Area called "Secure" and placed a new controller in it named HomeController. I then Created a new Home/Index.aspx view. However, when I browse to http://localhost/myapp/Secure/ it gives a 404 resource cannot be found. http://localhost/myapp/Secure/Home gives the same error.

我区登记看起来是这样的:

My area registration looks like this:

public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Secure_default",
                "Secure/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }

我也试过这样的:

I also tried this:

public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Secure_default",
                "Secure/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

谢谢,
贾斯汀

Thanks, Justin

推荐答案

当然,我有地区与ASP.NET MVC 2的工作。

Sure, i've got Areas working with ASP.NET MVC 2.

它的人很难调试路由随着SO,最简单的方法是你使用的菲尔Haacks路线调试器。它会告诉你路线(和地区)正在被解决什么特定的URL。非常方便。

Its hard for people to debug routes over SO, the easiest way is for you to use Phil Haacks Route Debugger. It'll tell you what routes (and areas) are being resolved for a particular URL. Extremely handy.

不过我带刺,试着改变你的路线,这样的:

However ill take a stab, try changing your route to this:

       context.MapRoute(
            "Secure_default",
            "Secure",
            new { action = "Index", controller = "Home", id = UrlParameter.Optional }
        );

的URL(< yourhost> /安全)会发现你的区域安全,但不知道是哪个控制器,你到手的请求,因为你没有指定一个默认值控制器在你的地区航线。

The url (<yourhost>/Secure) will find your area Secure but not know which controller you hand the request to, as you have not specified a default value for controller in your areas route.

下面是我的设置:

Areas
      Albums
           Controllers
                AlbumsController.cs (namespace Web.Areas.Albums.Controllers)
           Models
           Views
                Albums
                     Index.aspxx
           AlbumsAreaRegistration.cs
                context.MapRoute(
                    "Albums_Default",
                    "Albums",
                    new { controller = "Albums", action = "Index", id = UrlParameter.Optional)

的网址:的http://本地主机/相册触发我的AlbumsController中的指数行动在我的相册区域。

The URL: http://localhost/Albums triggers the "Index" action of my "AlbumsController" in my "Albums" area.

什么是你的结构是什么样子?

What does you structure look like?

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

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