加拿大家园论坛

Reference global master page from application pages

原文链接:https://forum.iask.ca/threads/97134/

admin : 2007-02-14#1
People are complaining that WSS 3 application pages (aspx pages in _layouts virtual directory) are not as easy as content pages to customize. The fact that the application pages are shared among all the sites prevents them from being customized for a specified site.

In addition, these application pages use another set of master pages rather than the global ones. In fact we cannot modify them statically to reference the global master pages such as default.master.

This is a problem for us when we decided to put our own pages into _layouts directory instead of using site template as we did in SharePoint 2003. Therefore we require these pages use the global master pages. Luckily, I came up with a trick that changes the reference to the global master page on the fly. The following code snippet does this, putting them in the application page, before any content tags.

<script runat="server">
protected override void OnPreInit(EventArgs e)
{
this.MasterPageFile = "/_catalogs/masterpage/default.master";

base.OnPreInit(e);
}
</script>