【发布时间】:2010-01-15 11:28:22
【问题描述】:
这是我长期潜伏后的第一篇文章-所以请温柔:-)
我有一个类似于 twitter 的网站,人们可以注册并选择一个“友好的 url”,所以在我的网站上他们会有类似的内容:
mydomain.com/benjones
我也有根级静态页面,例如:
mydomain.com/about
当然还有我的主页:
mydomain.com/
我是 ASP.NET MVC 2 的新手(实际上我今天才开始),我已经设置了以下路线来尝试实现上述目标。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("content/{*pathInfo}");
routes.IgnoreRoute("images/{*pathInfo}");
routes.MapRoute("About", "about",
new { controller = "Common", action = "About" }
);
// User profile sits at root level so check for this before displaying the homepage
routes.MapRoute("UserProfile", "{url}",
new { controller = "User", action = "Profile", url = "" }
);
routes.MapRoute("Home", "",
new { controller = "Home", action = "Index", id = "" }
);
}
在大多数情况下,这工作正常,但是,我的主页没有被触发!本质上,当您浏览到 mydomain.com 时,它似乎触发了带有空 {url} 参数的用户配置文件路由,因此永远无法访问主页!关于如何显示主页的任何想法?
【问题讨论】:
标签: asp.net asp.net-mvc routes