本文翻译自:Multiple types were found that match the controller named 'Home'

I currently have two unrelated MVC3 projects hosted online. 我目前有两个不相关的MVC3项目在线托管。

One works fine, the other doesn't work, giving me the error: 一个工作正常,另一个不工作,给我错误:

Multiple types were found that match the controller named 'Home'. 找到了多个与名为“ 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. 如果为该请求提供服务的路由('{controller} / {action} / {id}')未指定名称空间来搜索与该请求匹配的控制器,则可能会发生这种情况。

If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter. 如果是这种情况,请通过调用带有“名称空间”参数的“ MapRoute”方法的重载来注册此路由。

The way my hoster works is that he gives me FTP access and in that folder I have two other folder, one for each of my applications. 托管人的工作方式是,他为我提供FTP访问权限,在该文件夹中,我还有另外两个文件夹,每个文件夹用于我的每个应用程序。

ftpFolderA2/foo.com ftpFolderA2 / foo.com

ftpFolderA2/bar.com ftpFolderA2 / bar.com

foo.com works fine, I publish my application to my local file system then FTP the contents and it works. foo.com正常运行,我将应用程序发布到本地文件系统,然后通过FTP传输内容,并且可以正常工作。

When I upload and try to run bar.com, the issue above fires and prevents me from using my site. 当我上传并尝试运行bar.com时,上述问题触发,并阻止了我使用我的网站。 All while foo.com still works . 尽管foo.com仍然有效

Is bar.com searching from controllers EVERYWHERE inside of ftpFolderA2 and that's why it's finding another HomeController ? bar.com是否在ftpFolderA2内的任何地方从控制器进行搜索,这就是为什么它正在寻找另一个HomeController的原因? How can I tell it to only look in the Controller folder as it should? 我怎样才能告诉它只应在Controller文件夹中查找?

Facts: 事实:

  1. Not using areas. 不使用区域。 These are two COMPLETELY unrelated projects. 这是两个完全不相关的项目。 I place each published project into each respective folder. 我将每个已发布的项目放入每个相应的文件夹中。 Nothing fancy. 没有什么花哨。
  2. Each project only has 1 HomeController. 每个项目只有1个HomeController。

Can someone confirm this is the problem? 有人可以确认这是问题吗?


#1楼

参考:https://stackoom.com/question/Wu8b/找到多个与名为-Home-的控制器匹配的类型


#2楼

Another solution is to register a default namespace with ControllerBuilder. 另一个解决方案是向ControllerBuilder注册默认名称空间。 Since we had lots of routes in our main application and only a single generic route in our areas (where we were already specifying a namespace), we found this to be the easiest solution: 由于我们的主应用程序中有很多路由,而在我们的区域(我们已经指定了名称空间)中只有一条通用路由,因此我们发现这是最简单的解决方案:

ControllerBuilder.Current.DefaultNamespaces.Add("YourApp.Controllers");

#3楼

Watch this... http://www.asp.net/mvc/videos/mvc-2/how-do-i/aspnet-mvc-2-areas 观看此视频... http://www.asp.net/mvc/videos/mvc-2/how-do-i/aspnet-mvc-2-areas

Then this picture (hope u like my drawings) 然后这张照片(希望你喜欢我的画)


#4楼

Here is another scenario where you might confront this error. 这是您可能会遇到此错误的另一种情况。 If you rename your project so that the file name of the assembly changes, it's possible for you to have two versions of your ASP.NET assembly, which will reproduce this error. 如果重命名项目以使程序集的文件名更改,则可能有两个版本的ASP.NET程序集,它们将重现此错误。

The solution is to go to your bin folder and delete the old dlls. 解决方法是转到您的bin文件夹并删除旧的dll。 (I tried "Rebuild Project", but that didn't delete 'em, so do make sure to check bin to ensure they're gone) (我尝试过“重建项目”,但是并没有删除它们,因此请务必检查bin以确保它们消失了)


#5楼

You can also get the 500 error if you add your own assembly that contains the ApiController by overriding GetAssemblies of the DefaultAssembliesResolver and it is already in the array from base.GetAssemblies() 如果您通过覆盖DefaultAssembliesResolver的GetAssemblies来添加自己的包含ApiController的程序集,并且它已经位于base.GetAssemblies()的数组中,则也会出现500错误。

Case in point: 例子:

public class MyAssembliesResolver : DefaultAssembliesResolver
{public override ICollection<Assembly> GetAssemblies(){var baseAssemblies = base.GetAssemblies();var assemblies = new List<Assembly>(baseAssemblies);assemblies.Add(Assembly.GetAssembly(typeof(MyAssembliesResolver)));return new List<Assembly>(assemblies);}
}

if the above code is in the same assembly as your Controller, that assembly will be in the list twice and will generate a 500 error since the Web API doesn't know which one to use. 如果以上代码与Controller在同一程序集中,则该程序集将在列表中出现两次,并会产生500错误,因为Web API不知道使用哪个程序集。


#6楼

There might be another case with Areas even you have followed all steps in routing in Areas(like giving Namespaces in global routing table), which is: 即使您遵循了在区域中进行路由的所有步骤(例如在全局路由表中提供命名空间), 区域也可能存在另一种情况,即:

You might not have wrapped your Global Controller(s) in 'namespace' you provided in routing. 您可能没有将全局控制器包装在路由中提供的“名称空间”中。

Eg: 例如:

Done this: 完成此操作:

public class HomeController : Controller
{

Instead of: 代替:

namespace GivenNamespace.Controllers
{public class HomeController : Controller{

找到多个与名为“ Home”的控制器匹配的类型相关推荐

  1. 找到多个与名为“Home”的控制器匹配的类型

    /"应用程序中的服务器错误.找到多个与名为"Home"的控制器匹配的类型.如果为此请求("{controller}/{action}/{id}")提供 ...

  2. MVC area出现“找到多个与名为“Home”的控制器匹配的类型”错误的解决方法

    MVC area出现"找到多个与名为"Home"的控制器匹配的类型"错误的解决方法 参考文章: (1)MVC area出现"找到多个与名为" ...

  3. 未能找到服务器的主机名,未能找到服务器的主机名

    未能找到服务器的主机名 内容精选 换一换 访问IIS搭建的网站不通,报错404.IIS上绑定的域名只填写了主机名,没有指定IP地址.本节操作指导用户修改IIS上绑定的域名,以Windows Serve ...

  4. 未能找到该服务器列表,未能找到使用此主机名的服务器

    未能找到使用此主机名的服务器 内容精选 换一换 系统账号清理 将非登录用户的Shell设为/sbin/nologin usermod -s /sbin/nologin 用户名 锁定长期不使用的账号 u ...

  5. Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配...

    office版本:2016  系统版本:win10 问题描述:  1.桌面新建excel表格后,打开时,提示"Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效.请确定文件 ...

  6. Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配

    office版本:2016 系统版本:win10 问题描述: 1.桌面新建excel表格后,打开时,提示"Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效.请确定文件未损 ...

  7. Excel右键,新建工作表,打开时提示“因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。的**解决方案**

    Excel右键,新建工作表,打开时提示"因为文件格式或文件扩展名无效.请确定文件未损坏,并且文件扩展名与文件的格式匹配.的解决方案 如果你的电脑之前装过WPS,后来又卸载了,那么十有八九是路 ...

  8. 已解决Excel无法打开文件test.xIsx“,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。

    已解决Excel无法打开文件test.xIsx",因为文件格式或文件扩展名无效.请确定文件未损坏,并且文件扩展名与文件的格式匹配. 文章目录 报错代码 报错原因 解决方法 帮忙解决 报错代码 ...

  9. 打开excel显示php拓展名,phpexcel 导出excel 因为文件格式或文件扩展名无效,请确定文件未损坏,并且文件扩展名与文件的格式匹配...

    phpexcel导出excel:打开出现这个错误,强制打开是乱码 $objPHPExcel =newPHPExcel(); $filename ="test.xls"; heade ...

最新文章

  1. 处理WCF异常的方式
  2. HDU-1698 JUST A HOOK 线段树
  3. IE 中释放javascript对象
  4. Topforces Strikes Back
  5. ASP.NET Core MVC 之过滤器(Filter)
  6. 《ArcGIS Runtime SDK for .NET开发笔记》--三维功能
  7. 前端—每天5道面试题(1)
  8. 网络推广运营主要做些什么
  9. 自定义Writable类型
  10. 《编写高质量Python代码的59个有效方法》——第19条:用关键字参数来表达可选的行为...
  11. shell判断文件与字符串
  12. c语言指针和数组的转换,指针和数组的转换
  13. PHP和js做分页功能,php+js实现分页
  14. Thoughtworks笔试
  15. 成长的日记教案计算机,第一单元《成长日记ABC》教学设计
  16. Apache日志分割及分析
  17. 第一个被赋予公明身份的机器人_索菲亚成为首位被授予公民身份的机器人
  18. 做门户网站 个人站长的新好出路
  19. 基于PHP+MySQL音乐网站的设计与开发
  20. torch.load、torch.save、torch.optim.Adam的用法

热门文章

  1. OpenGL鼠标拾取
  2. LeakCanary 源码解析
  3. Android ADB被占用 重启 ADB方法
  4. python商业爬虫教程_廖雪峰老师的Python商业爬虫课程 Python网络爬虫实战教程 体会不一样的Python爬虫课程...
  5. Worker启动Executor源码
  6. 组件化开发和模块化开发概念辨析
  7. Java并发之公平锁
  8. 杨辉三角 用php写,PHP_PHP写杨辉三角实例代码,复制代码 代码如下: ?php // - phpStudy...
  9. electron 剪贴板 截图_用electron开发了一个屏幕截图工具
  10. [设计模式随意链接]——命令模式