2015-07-03 45 views
5

我正在使用SPA模板在Visual Studio中創建一個新項目。我的目標是擁有一個將「託管」/包含一些最終將被現代化/遷移的遺留應用程序的Angular/SPA應用程序。所以,我的SPA應用程序中的頁面上有一個iframe,當點擊一個菜單項時,我想在該iframe中加載一箇舊版ASP.NET應用程序(它必須位於iframe中,作爲舊版網站使用它們,其架構依賴於它們)。 我無法獲得路由權限。 SPA的模板定義這樣一個DefaultRoute類(我改變RouteExistingFiles爲true):無法在混合VS環境中正確處理路由

public class DefaultRoute : Route 
{ 
    public DefaultRoute() 
     : base("{*path}", new DefaultRouteHandler()) { 
     this.RouteExistingFiles = true; 
    } 
} 

,我編輯了RouteConfig.cs文件忽略 「ASPX」 頁面請求,就像這樣:

public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) { 
     routes.Ignore("*.aspx"); 
     routes.Add("Default", new DefaultRoute()); 
    } 
} 

定義了默認的路由處理,看起來是這樣的:

public class DefaultRouteHandler : IRouteHandler 
{ 
    public IHttpHandler GetHttpHandler(RequestContext requestContext) { 
     // Use cases: 
     //  ~/   -> ~/views/index.cshtml 
     //  ~/about  -> ~/views/about.cshtml or ~/views/about/index.cshtml 
     //  ~/views/about -> ~/views/about.cshtml 
     //  ~/xxx   -> ~/views/404.cshtml 
     var filePath = requestContext.HttpContext.Request.AppRelativeCurrentExecutionFilePath; 

     if (filePath == "~/") { 
      filePath = "~/views/index.cshtml"; 
     } 
     else { 
      if (!filePath.StartsWith("~/views/", StringComparison.OrdinalIgnoreCase)) { 
       filePath = filePath.Insert(2, "views/"); 
      } 

      if (!filePath.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase)) { 
       filePath = filePath += ".cshtml"; 
      } 
     } 

     var handler = WebPageHttpHandler.CreateFromVirtualPath(filePath); // returns NULL if .cshtml file wasn't found 

     if (handler == null) { 
      requestContext.RouteData.DataTokens.Add("templateUrl", "/views/404"); 
      handler = WebPageHttpHandler.CreateFromVirtualPath("~/views/404.cshtml"); 
     } 
     else { 
      requestContext.RouteData.DataTokens.Add("templateUrl", filePath.Substring(1, filePath.Length - 8)); 
     } 

     return handler; 
    } 
} 

的目錄結構是這樣的:

MySPA

  • SPA < - 包含SPA應用程序(.NET 4.5)

  • 舊版< - 包含遺留應用(.NET 3.0)

在IIS,我將舊文件夾設置爲SPA應用程序內的虛擬目錄(子目錄)。

如何設置路由,以便在單擊菜單項併發送請求(包含具有查詢字符串信息的url)時,可以將請求路由到舊應用程序?

回答

1

我已經解決了這個問題。這個問題是由幾個問題引起的。但是,大部分與我上面的信息有關的問題是這樣的......我需要找到正確的方式來忽略來自新網站路由代碼內的遺留aspx頁面的請求。所以,在RouteConfig.cs文件,我把這個忽略聲明爲RegisterRoute函數的第一行:

routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?"}); 

即糾正的主要問題,有跡象表明搞不清楚狀況,但是,我發現了其它一些小問題他們是什麼,我正在爲這些工作。因此,忽略路由功能中的遺留URL是正確的解決方案。