当使用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. 谈谈 Mifare Classic 破解

    2008 年的时候,荷兰恩智浦(NXP)公司开发的 RFID 产品 Mifare Classic 就被破解了,黑历史在这里就不在具体说了,想详细了解可以自己 Google 百度.现在还是重点说说关于 ...

  2. Cookies和Session的区别

    原文:http://www.cnblogs.com/lijihong/p/4743818.html 今天主要学习了Cookies和Session,网络上关于这方面的知识可谓很多,让人眼花缭乱,在此作一 ...

  3. UIWebView的缓存策略,清除cookie

    缓存策略 NSURLRequestCachePolicy NSURLRequestUseProtocolCachePolicy缓存策略定义在 web 协议实现中,用于请求特定的URL.是默认的URL缓 ...

  4. BZOJ 3165 Segment

    同上题. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...

  5. Bad Hair Day_单调栈

    Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow ...

  6. HDU 5820 (可持久化线段树)

    Problem Lights (HDU 5820) 题目大意 在一个大小为50000*50000的矩形中,有n个路灯.(n<=500000) 询问是否每一对路灯之间存在一条道路,使得长度为|x1 ...

  7. Linux基础入门(新版)(实验九-实验十二)

    实验九 简单文本入门 一.常用的文本处理命令 二.文本处理命令 1.tr 命令 tr 命令可以用来删除一段文本信息中的某些文字.或者将其进行转换. 使用方式: tr [option]...SET1 [ ...

  8. ASP.NET 中DataGrid item 绑定方法

    <Columns> <asp:TemplateColumn HeaderImageUrl="../../Images/delete.GIF"> <He ...

  9. Day05_JAVA语言基础第五天

    1.函数(掌握) 1.概念(掌握) 定义在类中,有特定功能的一小段程序 2.格式(掌握) 修饰符 返回类型 函数名(参数类型 形式参数,...){ 函数体: return 返回值; } 解释: A 修 ...

  10. cocos2d-html5 sprite打印宽高都为0的问题

    版本是2.1.4,在程序里直接通过图片路径addChild了一个cc.Sprite,想要缩放时通是不起做用,于是通过打印发现其宽,高都为0,查来查去,发现:原来是图片没有注册到Resource.js里 ...