当使用ASP.NET MVC的Area功能时,出现了这样的错误:
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:
MvcTest.Web.Controllers.HomeController 

MvcTest.Web.Areas.TestArea.Controllers.HomeController

这是因为你定义了两个HomeController(默认的一个,Area中一个),系统无法确定你默认的Controller=“Home”到底是哪一个。 

只需要在你的global.asax中的routes.MapRoute()方法中,添加一个默认的命名空间,如:
       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 = "" },  // Parameter defaults
               new string[] { "MvcTest.Web.Controllers" }
           );
       }
注意上面的new string[] { "MvcTest.Web.Controllers" }参数,在Area的对应AreaRegistration.cs类中的routes.MapRoute方法中,也加入这个参数,不同的是字符串要改写成Area的Controller对应的命名空间,如new[] { "MvcTest.Web.Areas.TestArea.Controllers" }

ASP.NET MVC报错: Multiple types were found that match the controller named的更多相关文章

  1. Multiple types were found that match the controller named 'Auth'.

    偶然的一个机会,修改了已经开发完毕的一个项目的命名.突然运行发现: { "Message": "An error has occurred.", "E ...

  2. MVC 区域内默认控制器不能访问(Multiple types were found that match the controller named ‘Index')

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 错误信息 和主页的默认控制器冲突了,修改下Areas里面的默认控制器就可以了

  3. Multiple types were found that match the controller named 'Home'. (weird error)

    found the error, because I changed the namespace and assembly name, then on the bin folder the old d ...

  4. 允许asp.net MVC报 错说明: 访问服务此请求所需的资源时出错。服务器可能未配置为访问所请求的 URL。错误消息 401.2。: 未经授权

    运行mvc3程序报以下错误 详细报错如下: “/”应用程序中的服务器错误. 访问被拒绝. 说明: 访问服务此请求所需的资源时出错.服务器可能未配置为访问所请求的 URL. 错误消息 401.2.: 未 ...

  5. iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容

    iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 提示里面的解决方法是: 如果不希望启用目录浏览,请确保配置了默认文档并且该文件存在. 使用 II ...

  6. ASP.NET MVC搭建项目后台UI框架—5、Demo演示Controller和View的交互

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  7. docker运行报错docker0: iptables: No chain/target/match by that name.

    转自:https://blog.csdn.net/wohaqiyi/article/details/84450562 docker运行报错docker0: iptables: No chain/tar ...

  8. 【手记】解决VS发布asp.net项目报错“该项目中不存在目标GatherAllFilesToPublish”及后续问题

    办法在最后. 用VS2017打开一个以前用VS2010写的asp.net项目后,设置好发布选项(发布到文件夹),发布的时候报错如图: 搜索一番,找到的办法是: 在项目文件(xxx.csproj)中,在 ...

  9. web.xml里报错:Multiple annotations found at this line:

    在web.xml 中添加错误页面配置,出现了这个报错 具体情况是这样的: 错误信息: Multiple annotations found at this line: - cvc-complex-ty ...

随机推荐

  1. 利用 Postfix 抵擋垃圾信

    reject_unknown_client               //add 20151117

  2. Response响应请求操作

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Te ...

  3. [转]Table-Driven and Data Driven Programming

    What is Table-Driven and Data-Driven Programming? Data/Table-Driven programming is the technique of ...

  4. Smart210学习记录-------linux驱动中断

    Linux中断 Linux 的中断处理分为两个半部,顶半部处理紧急的硬件操作,底半部处理不紧急的耗时操作.tasklet 和工作队列都是调度中断底半部的良好机制,tasklet 基于软中断实现.内核定 ...

  5. Mapnik 教程

    mapnik::parameters 参数解析 mapnik::parameters params; params["encoding"] = "utf-8" ...

  6. MapBox TileMill

    TileMill 学习网站: Walkthrough: Creating tiles with Mapnik using TileMill TileMill 快速入门 Cartography With ...

  7. CoreOS Linux available in China

    CoreOS Linux 竭诚服务中国用户 今天,我们宣布一个令人振奋的消息 - CoreOS Linux 开源版本正式向中国地区提供服务!国内的用户们现在可以使用安全.自动的 CoreOS Linu ...

  8. Java Servlet——改进的CGI

    一.关于Servlet 在上一篇随笔中,我们看到了CGI存在的不足,其每次请求都需加载和运行一个CGI程序.若使用Java编写CGI程序,需要为每个请求都启动一个系统进程以及JVM,其执行效率大大降低 ...

  9. [sql server发布订阅]after触发器执行失败造成复制不成功

    结论: (以插入而例) 发布端的数据插入成功 订阅段的数据不会插入 实验 创建一张新表 create table test_subscriber (id int, mark varchar(2),in ...

  10. C++ Vector 用法总结

    1, 头文件#include <vector> using namespace std; 2,定义与初始化 一般结合模板来使用 vector <Elem>           ...