2011-10-03 25 views
0

我想將此地址www.exmaple.com/my-profile重新路由到我的mvc應用程序中的配置文件控制器。還有就是我global.aspx,因爲你可以在默認路由是Asp.net Mvc 2如何重新路由到www.example.com/my-profile

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

這是圖路線我試圖用它來重新路由到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 
      ); 

問題是,當我輸入www.exmaple.com/profile時,它會將我指向默認的maproute,而不是我指定的那個。

但是,當我能做到這一點www.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 
      ); 

它工作正常,但我不想在我的輪廓添加會員。我希望它能像facebook.com/my-profile或youtube.com/my-profile一樣工作。

有誰人知道我是如何做到這一點,我一直在尋找一個超過2個月的解決方案(開和關)

感謝

回答

0

,如果我沒記錯的話將返回第一個匹配的模式你的路由爲URL。我希望在你的情況下,你的URL首先匹配你的默認模式。

將您的更具體的路線移動到「默認」路線上方,看看是否有幫助。

+0

嗨,我試着切換它們,但從來沒有工作。它試圖將跟隨「{**}/{**} /」模式的所有網址路由到我的個人資料頁面。 – user439525