2010-01-03 19 views

回答

1

如果您想從視圖文件夾以外的位置進行查看,則需要創建自己的ViewEngine

public class CustomViewEngine : WebFormViewEngine { 
    public CustomViewEngine() : base() { 

     MasterLocationFormats = new[] { 
      "/YourFolder/{1}/{0}.master", 
      "/YourFolder/Shared/{0}.master" 
     }; 

     ViewLocationFormats = new[] { 
      "/YourFolder/{1}/{0}.aspx", 
      "/YourFolder/{1}/{0}.ascx", 
      "/YourFolder/Shared/{0}.aspx", 
      "/YourFolder/Shared/{0}.ascx" 
     }; 

     PartialViewLocationFormats = ViewLocationFormats; 
    } 

    //Override the FindView method to implement your own logic 
    public override ViewEngineResult FindView(
     ControllerContext controllerContext, string viewName, 
     string masterName, bool useCache) 
     return base.FindView(controllerContext, viewName, masterName, useCache); 
    } 
} 

然後註冊您ViewEngineGlobal.asax

protected void Application_Start() { 
    ViewEngines.Engines.Clear(); 
    ViewEngines.Engines.Add(new CustomViewEngine()); 
} 

此外,this post可能會有所幫助。 (太糟糕了底部的下載鏈接被打破,雖然)

編輯:看來這個解決方案將在實踐中行不通,因爲ASP.NET將不允許從應用程序的目錄之外加載的內容(見Eilon的評論)。
但上面的鏈接,在DB中存儲視圖,仍然可能有所幫助。

+0

這在手不解決問題註冊您的視圖引擎。它仍然不會從其他應用程序(或從應用程序之外的任何文件夾)加載用戶控件。 – Eilon 2010-01-05 01:30:20

+0

@Eilon,你是不是指用戶控件共享視圖? – 2010-01-05 01:55:05

+0

我的意思是說你的解決方案只允許你將用戶控件放在* same *應用程序中的其他文件中。原始問題要求*多個*應用程序共享相同的用戶控件的能力。 – Eilon 2010-01-05 02:42:35

1

我不知道如何完成,但必須有一種方法來編譯DLL中的頁面並共享庫。

但是,如果你能負擔得起使用自定義視圖引擎和另一個模板系統(例如StringTemplate的),那麼你可以,如果你是共享庫共享訪問量:

相關問題