未找到 MVC3 资源 - 默认区域页面

发布于 2025-01-03 16:20:10 字数 1957 浏览 0 评论 0原文

这是一个奇怪的现象。

我已经开发了几个月的网络应用程序直到两天前都运行得非常好。

所讨论的基本结构由多个区域(主要问题涉及“管理”区域)、MVC 项目最高级别的默认控制器/视图和 Castle.Windsor DI 管道组成。

突然,管理部分的默认页面现在显示“找不到资源”消息。此消息与我是否通过 RedirectToAction(登录后)或通过菜单系统的标准返回 View(...) 访问此页面无关。

有人知道为什么这条特定路线不再有效吗?或者这里发生了什么事?

注意: - 其他区域默认路线映射仍然正确 - 我可以通过使用地址栏中的直接 url 来访问所有其他页面。 - 管理的默认路由(以及我需要的其他 8 个)在路由表

Global.asax 内容中显示正常:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterModelBinders();

        RegisterRoutes(RouteTable.Routes);

        ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(_container));

        BoostrapContainer();
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "LogOn", id = UrlParameter.Optional } 
        );
    }

管理区域注册:

public override string AreaName
        {
            get
            {
                return "Admin";
            }
        }

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

    );
}
  • 值得注意的是,对于管理注册,我尝试使用 a:< 显式指定命名空间/p>

    new { "xx.xx.xx.xx.Admin" }

但运气不佳。

但是,尝试输入 localhost/Admin 结果仍然找不到资源。

在此处输入图像描述

在此输入图像描述

This is an odd one.

A web app which I've been working on for a number of months has worked absolutely fine up until two days ago.

The basic structure in question comprises of a number of Areas (the main issue concerning the "Admin" area), a default Controller/View at the highest level of the MVC project and Castle.Windsor DI plumbing.

Out of the blue the default page for the Admin section now displays a "resource not found" message. This message is independant of whether i access this page via a RedirectToAction (after login) or via a standard return View(...) via menu system.

Does anyone have any reason why this particular route is no longer valid? Or whats going on here?

NB:
- The other area default routes map correctly still
- I am able to access every other page by using the direct url into the address bar.
- The default route for admin (and the 8 others i require) appear fine in the route table

Global.asax stuff:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterModelBinders();

        RegisterRoutes(RouteTable.Routes);

        ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(_container));

        BoostrapContainer();
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "LogOn", id = UrlParameter.Optional } 
        );
    }

Admin Area registration:

public override string AreaName
        {
            get
            {
                return "Admin";
            }
        }

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

    );
}
  • worth noting for the admin registration i've tried specifying the namespace explicitly with a:

    new { "xx.xx.xx.xx.Admin" }

But no luck.

However, trying to type localhost/Admin results still in a resource not found.

enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┾廆蒐ゝ 2025-01-10 16:20:10

使用 Phil Haack 编写的 RouteDebugger,并确保当你走那条路线,它不会先到达另一条路线。

路线是“先胜者胜”的事情。这包括区域注册。 RouteDebugger 将向您显示它认为路由的顺序。

将您的管理路由设置为:

context.MapRoute(
    "Admin Dashboard Route",
    "admin",
    new { area = admin, controller = "admindashboard", action = "dashboard" }
);

并将其放置在您的区域注册中。

它应该可以解决您的问题。

问题是你的路线不够具体。

它想要“Admin/something/something”,代码说,“好吧,如果“admin”/blank进来,它与“admin/something/something”路由不匹配,但它确实匹配“默认”路线。它会查看您已填写的段数,以及其中的内容(或未填写的内容)。

Use the RouteDebugger Phil Haack wrote, and ensure that when you go to that route, it's not hitting another route first.

Routes are a 'top one wins' affair. This includes Area registration. The RouteDebugger will show you what order it thinks the routes are in.

Make your admin route this:

context.MapRoute(
    "Admin Dashboard Route",
    "admin",
    new { area = admin, controller = "admindashboard", action = "dashboard" }
);

and place that in your area registration.

It should resolve your issue.

The problem is that your route isn't specific enough.

It wants, "Admin/something/something", and the code is saying, "Well, if "admin"/blank comes in, that doesn't match the "admin/something/something" route, but it does match the "default" route. It looks at the number of segments you have filled in, as well as what (or what's not) in them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文