2013-05-04 111 views
0

我試圖消除「家」形成了自己的網址,所以換句話說:無法獲取路由重命名URL

www.domain.com/home/about/變得www.domain.com/ aboutus

問題是,家庭沒有被刪除,我不能解決原因。我can see others have identical questions with near identical answers as to mine here on on SO所以我不知道爲什麼這不起作用。

我的Global.asax是

using System.Web.Http; 
using System.Web.Mvc; 
using System.Web.Routing; 

namespace Company.Ui 
{ 
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801 
    public class MvcApplication : System.Web.HttpApplication 
    { 
     protected void Application_Start() 
     { 
      AreaRegistration.RegisterAllAreas(); 

      WebApiConfig.Register(GlobalConfiguration.Configuration); 
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
      RouteConfig.RegisterRoutes(RouteTable.Routes); 
     } 

     public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

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


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

     } 
    } 
} 

我的ActionLink的代碼是:

@Html.ActionLink("About us", "AboutUs", "Home", null, new { @class = "mega" }) 

當我將鼠標懸停在一個鏈接,當我點擊鏈接,它仍然會返回www.domain.com \家\關於我們

我在調試模式下在Visual Studio中運行這個2012年

我在一個損失,任何人都可以幫忙嗎?

+0

請在您的帖子中顯示您的所有路線。你是否離開了'默認'?你有其他人嗎? – 2013-05-04 13:29:04

+0

@DaveA,我做了更新,並且顯示了我的整個Global.asax文件。只有2條路線。 – Dave 2013-05-04 13:52:52

+0

如果您刪除'Default'會發生什麼?它仍然使用'/ Home'渲染? – 2013-05-04 13:53:45

回答

1

我認爲你是在錯誤的地方你的路由工作,

從它似乎已註冊的路由在RouteConfig類中定義的代碼所示

protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas(); 

    WebApiConfig.Register(GlobalConfiguration.Configuration); 
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
    RouteConfig.RegisterRoutes(RouteTable.Routes); //routes are registered here 
} 

嘗試更換

RouteConfig.RegisterRoutes(RouteTable.Routes); 

RegisterRoutes(RouteTable.Routes); 

或編輯在RouteConfig

希望這可以幫助。

+0

你是對的我創建了一個新的MVC4應用程序,它將地圖註冊到App_Start文件夾中(默認情況下在VS中),我不得不將我的代碼複製到這個文件中,並且它已經工作了謝謝 – Dave 2013-05-05 06:29:03

+0

不用客氣 :) – shakib 2013-05-05 06:55:19