从 Layouts 目录运行 MasterPages
为了简化我们的 SharePoint 环境,我希望有一个存储所有母版页的中央单一位置,因此我希望直接从 _layouts 目录引用母版页文件。
我将文件添加到“\LAYOUTS\MyMasterPages”目录,然后更新 SPWeb 对象以使用该路径:
web.MasterUrl = "/_layouts/MyMasterPages/newdefault.master"
但是当我转到该站点时,我得到:
引用的文件 '/_layouts/MyMasterPages/newdefault.master' 此页面不允许。 在 System.Web.UI.TemplateParser.ProcessError(字符串 消息)在 System.Web.UI.BaseTemplateParser.GetReferencedType(虚拟路径 virtualPath,布尔值allowNoCompile)
在 System.Web.UI.PageParser.ProcessMainDirectiveAttribute(字符串 设备名称、字符串名称、字符串值、 IDictionary parseData)位于 System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary 主指令)
我假设这可能是由于信任级别安全策略和 CAS 配置造成的,但我不完全确定。 有没有办法允许这种在整个企业中使用母版页的集中方式,或者我是否坚持使用 /_catalog/ 虚拟路径?
To simplify our SharePoint environment I am wanting to have a central and single location where all of the master pages are stored so I was hoping to reference the masterpage files directly from the _layouts directory.
I add the files to the "\LAYOUTS\MyMasterPages" directory and then update the SPWeb object to use that path:
web.MasterUrl = "/_layouts/MyMasterPages/newdefault.master"
But when I go to the site I get:
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)
I am assuming that this may be due to trust level security policies and a CAS configuration but I am not entirely sure. Is there a way to allow this central way of using master pages across the enterprise or am I stuck using the /_catalog/ virtual path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用:
按照建议:
如何从 _layout SharePoint 使用网站的母版页页面?
This worked for me:
as proposed on:
How to use the site's masterpage from a _layout SharePoint page?
我的理解(但我不知道为什么)是母版页需要位于每个网站集的母版页库中。
由于您需要将这些包部署到场中的每个 SharePoint 服务器(前端、应用程序、数据库等),因此我认为该要求要么与集群相关,要么与数据库和重影相关。
无论哪种情况,无论您的场规模如何,请务必使用自定义功能作为部署母版页的方式。
我理解人们想要按照自己的方式使用 SharePoint 做事,虽然我通常持有这种想法,但过去一年的痛苦告诉我,生活在建议的 SharePoint 边界内是最好的方法。
My understanding (but I don't know why) is that Master Pages need to be in the MasterPage gallery of each site collection.
Since you would need to deploy those packages to each SharePoint server (frontend, application, database, etc) in the farm, I think the requirement is either related to clustering, or perhaps to the database and ghosting.
In either case, be sure to use custom features as the way you deploy your master pages regardless of your farm size.
I understand the want to do things your own way with SharePoint, and while I am normally on board with that kind of thinking, the past year of pain has taught me that living inside of the recommended SharePoint boundaries is the best way to go.
SharePoint 网站使用的母版页必须位于母版页库中。 据我所知,这是 SharePoint 的硬性要求。
这会给您带来比您想象的更多的好处。 这允许您使用 SharePoint 设计器实时更改母版页,并且更改仅对您可见。 一旦母版页签入并作为主要版本发布,更改就会对公众可见。 您还可以在母版页上查看版本历史记录。
我理解你的痛苦,我也遇到过和你一样的情况。 我学到的是:不要与平台对抗,只需在平台内工作即可。
The master page used by a SharePoint site must be located in the master page gallery. This is a hard requirement by SharePoint as far as I know.
This gives you more benefit than you might think. This allows you to change the master page in realtime using SharePoint designer with the changes only visible to you. Once the master page is check-in and published as a major version, the change becomes visible to the public. You also have version history on the master page.
I understand you pain, I have been in the same situation as you are. What I learned is: don't fight the platform, just work within it.