【问题标题】:The resource cannot be found using Area as separate project使用区域作为单独的项目无法找到资源
【发布时间】:2017-06-29 08:06:34
【问题描述】:

我想将区域用作单独的项目。每当我尝试导航到此链接时: http://localhost:100/module/home

我收到以下错误:

我的解决方案包含两个项目:实体框架和模块

我的解决方案如下:

module 是我想用作区域的项目。我的主要项目:

我在 entity_framework 中的 Route.config 看起来:

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

         routes.MapRoute(
             name: "Default",
             url: "{controller}/{action}/{id}",
             defaults: new { controller = "User", action = "Index", id = UrlParameter.Optional },
             namespaces:new string[] {"entity_framework.Controllers"}
         );
     }
 }

我的 moduleAreaRegistration.cs :

   namespace entity_framework
   {
       public class moduleAreaRegistration : AreaRegistration 
       {
           public override string AreaName 
           {
               get 
               {
                   return "module";
               }
           }

           public override void RegisterArea(AreaRegistrationContext context) 
           {
               context.MapRoute(
                   "module_default",
                   "module/{controller}/{action}/{id}",
                   new { action = "Index", id = UrlParameter.Optional },
                   new string[] {"entity_framework.Controllers"}
               );
           }
       }
   }

我也在项目和索引视图中的主控制器中添加了索引操作,但我陷入了这个错误。提前致谢。

【问题讨论】:

  • 区域注册码被调用了吗?你有什么?主项目是否引用区域项目?
  • @DavidG 先生,我已经编辑并显示了我的区域注册。您能看一次吗?
  • @DavidG 先生,您能帮我解决问题吗?我被困在其中。这是我通过并尝试创建模块化项目的链接:**geekswithblogs.net/cokobware/archive/2013/01/15/…**

标签: asp.net-mvc-4 asp.net-mvc-routing asp.net-mvc-areas


【解决方案1】:

我把命名空间改成了

new string[] { "module.Controllers" }                 

moduleAreaRegistration.cs 中。

然后我在主项目的 web.config 中添加了这个:

<appSettings>
    <add key="owin:AutomaticAppStartup" value="false" />
</appSettings>

这对我来说很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 2014-11-19
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多