开发者

Asp.net Mvc 2 How to reroute to www.example.com/my-profile

i would like to reroute this address www.exmaple.com/my-profile to a profile controller i have in my mvc application. There is my global.aspx, as you can the the default routing is

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

This is the Maproute i'm trying to use to reroute to www.exmaple.com/my-profile

routes.MapRoute(
                "Profile", // Route name
                "{profile_name}/", // URL with parameters
                new { controller = "Portfolio", action = "Index", page = UrlParameter.Optional } // Parameter defaults
            );

The problem is when i type www.exmaple.com/profile it trys to direct me to the default maproute, not the one i have specified.

But when i can do this ww开发者_开发技巧w.example.com/profile/my-profile

routes.MapRouteLowercase(
                "Profile", // Route name
                "profile/{profile_name}/", // URL with parameters
                new { controller = "Portfolio", action = "Index", page = UrlParameter.Optional } // Parameter defaults
            );

it works fine, but i dont want to add profile before my-profile. I would like it to work like facebook.com/my-profile or youtube.com/my-profile.

Does anyone one know how i accomplish this, i have been looking for a solution for over 2 months (on and off)

Thanks


Your routing if I remember rightly will return the first matching pattern for the URL. I would expect in your case, your URL is matching your default pattern first.

Move your more specific route above your 'default' route and see if this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜