Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在两个不同的区域找到了多个与名为“Home”的控制器匹配的类型_C#_Asp.net Mvc_Asp.net Mvc 3_Asp.net Mvc Routing - Fatal编程技术网

C# 在两个不同的区域找到了多个与名为“Home”的控制器匹配的类型

C# 在两个不同的区域找到了多个与名为“Home”的控制器匹配的类型,c#,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-routing,C#,Asp.net Mvc,Asp.net Mvc 3,Asp.net Mvc Routing,我的项目有两个方面。现在,当我运行该程序时,会出现以下错误: Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matche

我的项目有两个方面。现在,当我运行该程序时,会出现以下错误:

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Home' has found the following matching controllers:
BaseAdminMVC.Areas.BaseAdmin.Controllers.HomeController
BaseAdminMVC.Areas.TitomsAdmin.Controllers.HomeController  
我在这里找到了一些来源: 但我认为它只适用于一个领域。 就我而言,我有两个不同领域的项目。希望有人能告诉我该怎么解决这个问题。 以下是Global.asax文件:

顺便说一句,我也有控制器HomeController以外的地区文件夹。这只提供了指向两个项目BaseAdmin和TitomsAdmin的链接

我尝试过此解决方案,但仍然不起作用:


提前谢谢

我不知道会发生什么,但这段代码运行良好:

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 },
        new string[] { "BaseAdminMVC.Areas.TitomsAdmin.Controllers" }
    );
}

在重命名项目名称空间/程序集后,我出现了此错误


如果重命名了名称空间/程序集,则可能会在bin文件夹中保留以前名称的剩余程序集/dll。只要从那里删除它就可以了。

右键单击项目并选择“清理项目”。或者完全清空bin目录,然后重新构建。这将清除所有剩余的装配

重新编辑:您必须将默认路线下移到最后一个位置。秩序在这里很重要。@HenkHolterman仍然不起作用。什么不起作用还不清楚。是的。事实上,我已经解决了这个问题,但我不知道这个解决方案是如何成为可能的,而第一个解决方案是最有可能的,但不起作用。你说得对,秩序很重要。谢谢你的帮助!只是插嘴而已。。我知道已经晚了一年,但我收到了这个错误,因为我更改了输出程序集的名称和默认名称空间。我将MVC3站点中的旧编译程序集保留在项目的debug/bin文件夹中,但没有意识到这一点。当站点加载时,它从旧程序集和新重命名的程序集中拾取主控制器,并抛出与您相同的错误。长话短说,我走进垃圾箱,拆除了旧的组件,一切都开始正常工作。谢谢!我现在正从4.0迁移到.NET4.5。若同样的错误再次出现,你们的提示可能会有所帮助。@我知道我不应该在评论中说谢谢,但FU-*-谢谢!当然,此注释需要是对此的默认答案。对于ASP.NETMVC5仍然适用。@OFConsulting:您的解决方案对我来说是正确的。尽管我可以指定名称空间,但我宁愿解决根本原因以避免将来的混乱。也就是说,如果有人真的需要在同一名称空间中有两个控制器,那么他们应该使用上面的答案。
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                "BaseAdmin",
                "BaseAdmin/{controller}/{action}",
                new { controller = "Account", action = "Index" },
                new string[] { "BaseAdminMVC.Areas.BaseAdmin.Controllers" }
            );

            routes.MapRoute(
                "TitomsAdmin",
                "TitomsAdmin/{controller}/{action}",
                new { controller = "Home", action = "Index" },
                new string[] { "BaseAdminMVC.Areas.TitomsAdmin.Controllers" }
            );
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 },
        new string[] { "BaseAdminMVC.Areas.TitomsAdmin.Controllers" }
    );
}