创建自定义路由以在网站的根目录进行映射

时间:2013-05-07 14:28:29

标签: c# asp.net-mvc-4

我的routeConfig.cs文件目前有:

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

我的家庭控制器中有一个动作响应:

/home/trackUser/123

如何修改我的路由配置,以便在以下位置调用相同的操作:

/trackUser.aspx?userId=123

1 个答案:

答案 0 :(得分:0)

现在无法检查,但试试这个:

routes.MapRoute(
                name: "TrackUserAspx",
                url: "/trackUser.aspx?userId={id}",
                defaults: new { controller = "Home", action = "trackUser", id = UrlParameter.Optional }
            );

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