gpt4 book ai didi

C# MVC 5 多个路由不工作服务器

转载 作者:行者123 更新时间:2023-11-30 14:23:32 24 4
gpt4 key购买 nike

我有一个项目,我试图使映射“短”以使 Urls 看起来漂亮。

在我的环境中,它可以正常工作,但是当发布到服务器时,它会出现以下错误。

我的网站网址: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

Visual Studio

enter image description here

最佳答案

您需要将命名空间添加到路由中,以指示您想要哪个 BlogController,即:

routes.MapRoute(
name: "Secao",
url: "Secao/{id}",
defaults: new { controller = "Blog", action = "Secao" },
namespaces: new[] { "PapoDeAlemao.Controllers" }
);

关于C# MVC 5 多个路由不工作服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45087102/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com