C # MVC 5 Multiple routes server down
I have a project where I was trying to make the display "short" in order to make the Urls look nice.
In my environment it works, however when publishing to server it gives below error.
My site url: www.papodealemao.com.br
My routes
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 }
);
}
Mistake
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
Visual Studio
source to share
The reason for the error is that you have classes named " BlogController
" once inside the Controllers folder and one inside the PapoDeAlemao / Controllers folder. Please combine in one class and the error will go away.
OR
You can skip name routing
routes.MapRoute(
name: "Secao",
url: "Secao/{id}",
defaults: new { controller = "Blog", action = "Secao" },
namespaces: new[] { "PapoDeAlemao.Controllers" }
);
source to share
The error message indicates that you have multiple named classes BlogController
and the route table doesn't know which one you want to redirect to. Maybe this is some parasitic code that you wanted to remove. There might also be an old DLL left on the server that still references old code.
Try cleaning up the previous files and republishing them.
source to share