2010-01-03 84 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的),那么你可以,如果你是共享库共享访问量:

相关问题