当前位置:首页>编程日记>正文

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

本文翻译自: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) 然后这张照片(希望你喜欢我的画)

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


#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{

http://www.coolblog.cn/news/85b36d84e9d6aad8.html

相关文章:

  • asp多表查询并显示_SpringBoot系列(五):SpringBoot整合Mybatis实现多表关联查询
  • s7day2学习记录
  • 【求锤得锤的故事】Redis锁从面试连环炮聊到神仙打架。
  • 矿Spring入门Demo
  • 拼音怎么写_老师:不会写的字用圈代替,看到孩子试卷,网友:人才
  • Linux 实时流量监测(iptraf中文图解)
  • Win10 + Python + GPU版MXNet + VS2015 + RTools + R配置
  • 美颜
  • shell访问php文件夹,Shell获取某目录下所有文件夹的名称
  • 如何优雅的实现 Spring Boot 接口参数加密解密?
  • LeCun亲授的深度学习入门课:从飞行器的发明到卷积神经网络
  • Mac原生Terminal快速登录ssh
  • java受保护的数据与_Javascript类定义语法,私有成员、受保护成员、静态成员等介绍...
  • mysql commit 机制_1024MySQL事物提交机制
  • 支撑微博千亿调用的轻量级RPC框架:Motan
  • jquery 使用小技巧
  • 2019-9
  • 法拉利虚拟学院2010 服务器,法拉利虚拟学院2010
  • vscode pylint 错误_将实际未错误的py库添加到pylint白名单
  • 科学计算工具NumPy(3):ndarray的元素处理
  • 工程师在工作电脑存 64G 不雅文件,被公司开除后索赔 41 万,结果…
  • linux批量创建用户和密码
  • newinsets用法java_Java XYPlot.setInsets方法代碼示例
  • js常用阻止冒泡事件
  • 气泡图在开源监控工具中的应用效果
  • 各类型土地利用图例_划重点!国土空间总体规划——土地利用
  • php 启动服务器监听
  • dubbo简单示例
  • 【设计模式】 模式PK:策略模式VS状态模式
  • [iptables]Redhat 7.2下使用iptables实现NAT
  • Ubuntu13.10:[3]如何开启SSH SERVER服务
  • CSS小技巧——CSS滚动条美化
  • JS实现-页面数据无限加载
  • 阿里巴巴分布式服务框架 Dubbo
  • 最新DOS大全
  • Django View(视图系统)
  • 阿里大鱼.net core 发送短信
  • 程序员入错行怎么办?
  • 两张超级大表join优化
  • 第九天函数
  • Linux软件安装-----apache安装
  • HDU 5988 最小费用流
  • Sorenson Capital:值得投资的 5 种 AI 技术
  • 《看透springmvc源码分析与实践》读书笔记一
  • 正式开课!如何学习相机模型与标定?(单目+双目+鱼眼+深度相机)
  • Arm芯片的新革命在缓缓上演
  • nagios自写插件—check_file
  • python3 错误 Max retries exceeded with url 解决方法
  • 行为模式之Template Method模式
  • 通过Spark进行ALS离线和Stream实时推荐