gpt4 book ai didi

asp.net-mvc-4 - MVC 路由不起作用

转载 作者:行者123 更新时间:2023-12-04 05:51:50 24 4
gpt4 key购买 nike

在我的路由配置类中,我创建了一个带有 static 前缀的自定义路由配置,

public static void RegisterRoutes(RouteCollection routes) { 
routes.MapRoute("MyRoute", "{controller}/{action}",
new { controller = "Home", action = "Index" });
routes.MapRoute("", "Public/{controller}/{action}",
new { controller = "Home", action = "Index" });
}

但是 URL ...mysite/Public 给出了一个找不到页面 错误。这里有什么问题?

最佳答案

改变两条路线的顺序,

 public static void RegisterRoutes(RouteCollection routes) { 

routes.MapRoute("", "Public/{controller}/{action}",
new { controller = "Home", action = "Index" });

routes.MapRoute("MyRoute", "{controller}/{action}",
new { controller = "Home", action = "Index" });

}

MVC 路由根据给定顺序遍历匹配模式。它正在尝试生成一个 URL 作为 Public/index,但未找到。

关于asp.net-mvc-4 - MVC 路由不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20779264/

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