故障排除“找不到资源。”错误
我有一个 MVC 3 应用程序,其中内置了几个区域,其中一个区域是我网站的管理部分。一切都工作得很好。我想尝试 MvcContrib Portable Areas 来使我的应用程序更加模块化,因此我安装了 MvcContrib,经过一番尝试和错误后,我启动并运行了几个可移植区域。
然后我决定将我的管理区域移动到可移植区域,因此我创建了新项目并删除了我的管理可移植区域。我必须重命名本地管理区域,以免发生冲突。在将一些代码移至管理 PA 时,我决定不想因为将所有 Telerik 和其他已连接到管理区域的东西而感到头疼。所以我把东西移回到主项目区域并删除了管理 PA。
我重新连接了管理区域,并检查了与设置区域相关的所有内容。现在,在我的一生中,我无法加载主项目中的任何区域。我不断收到“找不到资源”的消息。错误信息。
我什至删除了对 MvcContrib 和 Portable Areas 的引用,但仍然没有成功。我已经束手无策了,因为我不知道如何调试它。我使用了自定义路由处理程序以及 Glimpse,但在引发错误时两者都不是很有用。
这是我的 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" }
);
这是我的管理区域注册文件中的路由
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "CoolProject.Web.Areas.Admin.Contollers" }
);
这是我的 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"));
}
我已经针对类似的工作站点检查了我的设置,除了命名空间和类之外,一切都相同。
我正在 Win 7 IIS7.5 上
使用 Glimpse Routes 插件进行开发,我可以看到路由存在,但问题是我的 Global.axas 文件中的路由正在接管对这些区域的所有请求。
我需要对我的路线做什么才能让核心应用程序和区域相处?有趣的是我有另一个生产应用程序使用工作正常的区域。
更新....
我创建了一个新的 MVC 3 项目,添加了一个名为 Admin 的区域。然后我编辑了 AdminAreaRegistration.cs 和 Global.asax 文件以将命名空间包含在 MapRoute 语句中,对其进行编译并完美运行。我可以毫无问题地访问该区域。
然后,我将 Global.asax 和 AdminAreaRegistration.cs 与我损坏的项目中的文件进行了比较,它们是相同的。这不是我如何设置路线的问题,我认为还有另一个我没有看到的问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用
AreaRegistration.RegisterAllAreas();
您是否在 Global.asax 中的 Application_Start 上 ?您使用什么服务器来开发 Cassini、IISExpress、IIS?
查看更详细的信息后进行编辑。
在您的管理区域注册文件中,如果您有此代码,
我认为“CoolProject.Web.Areas.Admin.Contollers”中有一个拼写错误,它应该是“CoolProject.Web.Areas.Admin.Controllers”?
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
I think there is a typo in "CoolProject.Web.Areas.Admin.Contollers" and it should be "CoolProject.Web.Areas.Admin.Controllers"?
确保您的控制器中的命名空间也正确。例如,如果您通过从另一个 MVC 应用程序复制 MVC 组件来创建新区域(就像我所做的那样),很容易忘记更改命名空间!
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!