如何使Layouts裏的頁面應用站點母板頁

今天有個朋友問這個問題,寫一下~

很簡單,只要在頁面的OnPreInit方法裏動態設置MasterPageFile 屬性爲當前站點的MasterUrl即可: 

protected override void OnPreInit(EventArgs e)
    {
        
base.OnPreInit(e);

        
if (SPContext.Current != null)
            Page.MasterPageFile 
= SPContext.Current.Web.MasterUrl;
    }

 

在aspx裏就要這麼寫: 

<script runat="server">
    
    protected override 
void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        
this.MasterPageFile = base.Web.MasterUrl;
    } 
    
</script>

 

 自己開發的頁面如果運行在SharePoint環境下也可這樣來實現母板頁的統一。

發佈了75 篇原創文章 · 獲贊 5 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章