2015-10-17 19 views
0

我有一個既有整合MVC5和Webforms的應用程序。我正在將其從WebForms轉換爲MVC,一次只能一步。在添加我的控制器,vies等之後,我添加了我的MVC路由,如下所示。但由於某種原因,當我啓動應用程序(F5)時,Default.aspx頁面仍然會打開,而不是我的主頁/索引。我究竟做錯了什麼?MVC混合仍然調用default.aspx

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

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

編輯:我只是想通了,但不明白爲什麼。看起來,當我轉到項目的屬性並將服務器設置爲「使用Visual Studio Development Server」時,它會在啓動時顯示我的Default.aspx頁面。但是,當我將其更改爲「使用本地IIS Web服務器」時,MVC Url路由就會啓動並打開我的Home \ Index頁面。誰可以給我解釋一下這個?

回答

0

只有在註釋掉Application_Start中的路由註冊時,我才能重現上述行爲(請參閱下面我的Global.asax中的註釋行)。否則,它在webforms和mvc5混合項目樣例中工作得很好。

這裏是我的Global.asax

void Application_Start(object sender, EventArgs e) 
     { 
      // Code that runs on application startup 
      AreaRegistration.RegisterAllAreas(); 
      //GlobalConfiguration.Configure(WebApiConfig.Register); 
      //RouteConfig.RegisterRoutes(RouteTable.Routes); 
      BundleConfig.RegisterBundles(BundleTable.Bundles);    
     } 

這裏是我的RouteConfig

public static void RegisterRoutes(RouteCollection routes) 
     { 
      var settings = new FriendlyUrlSettings(); 
      settings.AutoRedirectMode = RedirectMode.Permanent; 
      routes.EnableFriendlyUrls(settings); 

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

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

我增加了更多的細節,我的問題。我可以通過更改項目屬性中的服務器來重現行爲。但我不明白它爲什麼這樣做。 – Ray

+0

您在項目屬性 - > Web部分中顯示的開始操作是什麼? – curiousgeek

+0

開始操作設置爲特定頁面,但爲空。 – Ray