为了简化我们的 SharePoint 环境,我希望有一个集中的单一位置来存储所有母版页,因此我希望直接从 _layouts 目录引用母版页文件。
我将文件添加到“\LAYOUTS\MyMasterPages”目录,然后更新 SPWeb 对象以使用该路径:
web.MasterUrl = "/_layouts/MyMasterPages/newdefault.master"
但是当我访问该网站时,我得到:
The referenced file '/_layouts/MyMasterPages/newdefault.master' is not allowed on this page. at System.Web.UI.TemplateParser.ProcessError(String message) at System.Web.UI.BaseTemplateParser.GetReferencedType(VirtualPath virtualPath, Boolean allowNoCompile)
at System.Web.UI.PageParser.ProcessMainDirectiveAttribute(String deviceName, String name, String value, IDictionary parseData) at System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary mainDirective)
我假设这可能是由于信任级别的安全策略和 CAS 配置,但我不完全确定。有没有办法允许这种在整个企业中使用母版页的集中方式,或者我是否一直在使用/_catalog/虚拟路径?
最佳答案
这对我有用:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.MasterPageFile = "path to masterpage";
}
建议于: How to use the site's masterpage from a _layout SharePoint page?
关于sharepoint - 从 Layouts 目录运行 MasterPages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/786409/