多种类型的发现命名为'家'控制器匹配 [英] Multiple types were found that match the controller named 'Home'

查看:146
本文介绍了多种类型的发现命名为'家'控制器匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有在线托管两个不相干的MVC3项目。

I currently have two unrelated MVC3 projects hosted online.

一工作正常,其他不工作,给我的错误:

One works fine, the other doesn't work, giving me the error:

多种类型的发现命名为'家'控制器匹配。这个
  如果路由服务此请求可能发生
  ('{控制器} / {行动} / {ID}')不指定命名空间搜索
  对于控制器的要求相匹配。

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.

我的主机供应商的工作方式是,他给我的FTP访问和该文件夹中我有两个其他文件夹,每一个我的应用程序。

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.

ftpFolderA2 / foo.com

ftpFolderA2/foo.com

ftpFolderA2 / bar.com

ftpFolderA2/bar.com

foo.com工作得很好,我出版我的应用程序到我的本地文件系统,然后FTP的内容和它的作品。

foo.com works fine, I publish my application to my local file system then FTP the contents and it works.

当我上传和尝试运行bar.com,上述火灾和$ P $问题pvents我使用我的网站。 所有同时foo.com仍然有效

When I upload and try to run bar.com, the issue above fires and prevents me from using my site. All while foo.com still works.

时bar.com从控制器到处搜寻,里面ftpFolderA2的,这就是为什么它寻找另一个的HomeController ?我怎么能告诉它只是在控制器文件夹看看,因为它应该?

Is bar.com searching from controllers EVERYWHERE inside of ftpFolderA2 and that's why it's finding another HomeController? How can I tell it to only look in the Controller folder as it should?

事实:


  1. 不使用的区域。这是两个完全不相关的项目。我把每一个发布的项目到每个相应的文件夹中。没什么特别的。

  2. 每个项目只有1 HomeController中。

有人可以证实这是什么问题?

Can someone confirm this is the problem?

推荐答案

在使用方面,你有区域和根内相同的控制器名称此错误消息经常发生。例如,你有两个:

This error message often happens when you use areas and you have the same controller name inside the area and the root. For example you have the two:


  • 〜/控制器/ HomeController.cs

  • 〜/地区/行政/控制器/ HomeController.cs

  • ~/Controllers/HomeController.cs
  • ~/Areas/Admin/Controllers/HomeController.cs

为了解决这个问题(作为错误信息提示你),你可以声明你的路由时所使用的命名空间。因此,在主路由定义在的Global.asax

In order to resolve this issue (as the error message suggests you), you could use namespaces when declaring your routes. So in the main route definition in Global.asax:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new[] { "AppName.Controllers" }
);

和在〜/地区/行政/ AdminAreaRegistration.cs

context.MapRoute(
    "Admin_default",
    "Admin/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional },
    new[] { "AppName.Areas.Admin.Controllers" }
);

如果你不使用的区域看来你这两个应用程序相同的ASP.NET应用程序内托管并发生冲突,因为您在不同的命名空间中的定义相同的控制器。你将必须配置,如果你想避免这类冲突IIS来承载这两个作为单独的ASP.NET应用程序。询问有关此您的托管服务提供商,如果你没有访问该服务器。

If you are not using areas it seems that your both applications are hosted inside the same ASP.NET application and conflicts occur because you have the same controllers defined in different namespaces. You will have to configure IIS to host those two as separate ASP.NET applications if you want to avoid such kind of conflicts. Ask your hosting provider for this if you don't have access to the server.

这篇关于多种类型的发现命名为'家'控制器匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆