gpt4 book ai didi

asp.net-mvc - 如何更改 MVC5 中的默认 URL

转载 作者:行者123 更新时间:2023-12-02 01:29:04 26 4
gpt4 key购买 nike

我的routeconfig.cs 文件中有一个默认路由

 routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

它会在浏览器中隐藏 Home/Index 作为 Url。我的目标是显示 localhost:44300/Login 而不是 localhost:44300/Home/Index (但在内部它会调用 Home/Index)我想将 Home/Details 操作方法隐藏为 url

最佳答案

您可以将默认路由更改为 Account Controller 和必要的 Action 方法:

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id =
UrlParameter.Optional }
);

更新:

这是不可能的,因为 MVC 有一个约定 RouteTable 应该是这样的:controller/action 反之亦然。

如果你从路由中排除 Controller ,你会得到一个异常:

The matched route does not include a 'controller' route value, which is required.

关于asp.net-mvc - 如何更改 MVC5 中的默认 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35193552/

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