Troubleshooting “The resource cannot be found.” Er

2019-02-15 03:53发布

I have an MVC 3 App with a few Areas built into it, one of the areas is my Admin section of my site. Everything was working just fine. I wanted to try MvcContrib Portable Areas to make my app more modular, so I installed MvcContrib and after some trial and error I got a couple Portable areas up and running.

Then I decided to move my Admin area up into a portable area, so i created the new project and stubbed out my Admin portable area. I had to rename my local Admin Area so that it would not conflict. While moving some code up to the Admin PA I decided that I did not want the headache of moving all the Telerik and other things I had wired up to my Admin area. SO I moved things back down to the main project Area and deleted the Admin PA.

I rewired my Admin Area back in and went over everything involved in setting up an Area. Now for the life of me I cannot get any of my areas in my main project to load. I keep getting the "The resource cannot be found." error message.

I even went as far as removing the reference to MvcContrib and Portable Areas but still no luck. I am at the end of my rope as I do not know how to debug this. I have used a custom route handler as well as Glimpse but neither are very useful when the error is thrown.

Here is the route in my global.asax

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
            null,
            new string[] { "CoolProject.Web.Controllers" }
        );

here is the route in my admin area registration file

context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            new string[] { "CoolProject.Web.Areas.Admin.Contollers" }
        );

here is my Global.asax

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

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
            new string[] { "CoolProject.Web.Controllers" }
        );

    }

    protected void Application_Start() 
    {

        AreaRegistration.RegisterAllAreas();
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
        InitializeContainer();
        AppStart_Structuremap.Start();

        SiteMapManager.SiteMaps.Register<XmlSiteMap>("AdminNavigation", sitemap => sitemap.LoadFrom("/Areas/Admin/AdminNavigation.sitemap"));

    }

I have checked my setup against a similar working site and everything is the same with the exception of namespaces and classes.

I am developing on Win 7 IIS7.5

Using Glimpse Routes plugin I can see that the routes exist but the problem is that the route in my Global.axas file is taking over all the requests to the areas.

What do I need to do with my routes to allow for the core app and the areas to get along? The funny thing is I have another production app using areas that works just fine.

Update....

I created a new MVC 3 Project, Added a single area named Admin. Then I edited the AdminAreaRegistration.cs and Global.asax files to include the namespaces in the MapRoute statement, compiled it and it runs perfectly. I can access the area with no problem.

I then compared the Global.asax and AdminAreaRegistration.cs with the files in my broken project and they are Identical. This is not an issue with how I set up my routes, I think there is another problem that I am not seeing.

2条回答
何必那么认真
2楼-- · 2019-02-15 04:24

Make sure the namespace is correct in your Controller, as well. If you created the new Area by copying MVC components from another MVC application, for instance (as I did) it's easy to forget to change the namespace!

查看更多
Luminary・发光体
3楼-- · 2019-02-15 04:27

Are you calling

AreaRegistration.RegisterAllAreas();

on Application_Start in your Global.asax? What server are you using for development Cassini, IISExpress, IIS?

Edit after reviewing more detailed information.

In your Admin Area Registration File if you have this code

context.MapRoute(
        "Admin_default",
        "Admin/{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        new string[] { "CoolProject.Web.Areas.Admin.Contollers" }
    );

I think there is a typo in "CoolProject.Web.Areas.Admin.Contollers" and it should be "CoolProject.Web.Areas.Admin.Controllers"?

查看更多
登录 后发表回答