我有一个项目,我试图进行映射"简短"让网址看起来很漂亮。
在我的环境中它正在运行,但是当发布到服务器时,它会给出以下错误。
我的网站:www.papodealemao.com.br
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Pagina",
url: "pagina/{id}",
defaults: new { controller = "Principal", action = "Index", id = "1" }
);
routes.MapRoute(
name: "Secao",
url: "Secao/{id}",
defaults: new { controller = "Blog", action = "Secao" }
);
routes.MapRoute(
name: "Categoria",
url: "Categoria/{id}",
defaults: new { controller = "Blog", action = "Categoria" }
);
routes.MapRoute(
name: "PorData",
url: "PorData/{id}",
defaults: new { controller = "Blog", action = "PorData" }
);
routes.MapRoute(
name: "Artigo",
url: "artigo/{id}",
defaults: new { controller = "Blog", action = "Artigo" }
);
routes.MapRoute(
name: "Tag",
url: "Tag/{id}",
defaults: new { controller = "Blog", action = "Tag" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Principal", action = "Index", id = UrlParameter.Optional }
);
}
Multiple types were found that match the controller named 'Blog'. This can happen if the route that services this request ('artigo/{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 'Blog' has found the following matching controllers:
PapoDeAlemao.Controllers.BlogController
blog.Controllers.BlogController
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Multiple types were found that match the controller named 'Blog'. This can happen if the route that services this request ('artigo/{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 'Blog' has found the following matching controllers:
PapoDeAlemao.Controllers.BlogController
blog.Controllers.BlogController
答案 0 :(得分:4)
您需要在路线中添加名称空间,指明您想要的routes.MapRoute(
name: "Secao",
url: "Secao/{id}",
defaults: new { controller = "Blog", action = "Secao" },
namespaces: new[] { "PapoDeAlemao.Controllers" }
);
,即:
public interface ICurrentContextProvider<T>
{
T GetCurrentUser();
}
答案 1 :(得分:1)
错误的原因是您必须使用名为&#34; BlogController
&#34;的类。一旦进入内部&#34;控制器&#34;文件夹和一个内部&#34; PapoDeAlemao / Controllers&#34;夹。请在一个班级统一,错误将消失。
OR
您可以命名空间路由
routes.MapRoute(
name: "Secao",
url: "Secao/{id}",
defaults: new { controller = "Blog", action = "Secao" },
namespaces: new[] { "PapoDeAlemao.Controllers" }
);
答案 2 :(得分:1)
错误消息表明您有多个名为BlogController
的类,并且路由表不知道您要路由到哪个类。可能是你要删除的杂散代码。也可能是仍在引用旧代码的服务器上留下的旧dll。
尝试清除以前的文件并重新发布。