gpt4 book ai didi

asp.net-mvc - ASP.NET MVC 路由 - "Blank"路由

转载 作者:行者123 更新时间:2023-12-02 05:39:38 27 4
gpt4 key购买 nike

我可以设置一条从根级 URL 进行映射的路由吗?

http://localhost:49658/

我使用的是 VS2010 内置 Web 服务器。

尝试使用空白或单斜杠 URL 字符串设置路由不起作用:

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

这会导致错误“路由 URL 不能以 '/' 或 '~' 字符开头,并且不能包含 '?'特点。”。提前致谢!我的整个路线定义在这里:

    public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"EditingTitles", // Route name
"{controller}/{action}/{startingLetter}", // URL with parameters
new { controller = "Admin", action = "Index", startingLetter = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}

最佳答案

您想在这里实现什么...看起来像这样的 URL? http://www.acme.com/ ?因为如果是的话,当没有指定任何参数时,默认路由将实现这一点。

// Default Route:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = String.Empty } // Parameter defaults
);

关于asp.net-mvc - ASP.NET MVC 路由 - "Blank"路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4087861/

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