这是我作为长期潜伏者之后的第一篇文章 – 所以请温柔:-)
我有一个类似于twitter的网站,人们可以注册并选择一个“友好的网址”,所以在我的网站上他们会有类似的东西:
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}参数的User Profile路由,因此永远不会到达主页!关于如何显示主页的任何想法?
解决方法
你能不换掉最后两条路线吗?