ASP.NET MVC twitter / myspace样式路由

这是我作为长期潜伏者之后的第一篇文章 – 所以请温柔:-)

我有一个类似于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路由,因此永远不会到达主页!关于如何显示主页的任何想法?

解决方法

你能不换掉最后两条路线吗?

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....