我想將此地址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個月的解決方案(開和關)
感謝
嗨,我試着切換它們,但從來沒有工作。它試圖將跟隨「{**}/{**} /」模式的所有網址路由到我的個人資料頁面。 – user439525