接觸過Sharepoint開發的小夥伴,大部分應該都開發過Sharepoint Solution,在開發Sharepoint Solution的時候,咱們每每但願咱們所開發的Page使用咱們本身的樣式而不是使用Sharepoint自帶的,所以就須要咱們本身自定義咱們的MasterPage。在自定義的過程當中主要包含兩種自定義模式,一種是在自定義的Master Page中包含Sharepoint元素的,例如保留了Sharepoint自帶的頭部的toolbar,一種是徹底自定義的Master Page, 即不包含任何Sharepoint元素,本篇文章主要介紹一下第二種方式,徹底自定義Master Page。html
Sharepoint自身提供了Sharepoint Designer這個工具用來設計和管理Sharepoint中的相關元素,其中就包含了對Master Page的設計和管理,咱們能夠經過Sharepoint Designer新建一個Blank Master Page, 如圖所示:react
經過New Blank Master Page咱們能夠建立出來一個名爲test.master的不包含任何Sharepoint元素的Master Page, 以下所示:app
<%@ Master Language="C#" %>
<html dir="ltr">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled 1</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:ContentPlaceHolder id="PlaceHolderMain" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>複製代碼
其中asp標籤的內容你們能夠理解爲佔位符,當咱們經過子頁面引用master page的時候,就會用子頁面中的內容來替換佔位符的部分,例如咱們建立一個名爲Index.aspx的Application Page,內部代碼以下所示:工具
<%@ Page Language="C#" MasterPageFile="../../MasterPage/test.master" %>
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderID="head" runat="server">
<script src="test.js"></script>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
this is content
</asp:Content>複製代碼
如上所示的代碼中,Index.aspx會以test.master爲master page,頁面中asp標籤中ContentPlaceHolderID值爲head的部分將會替換master page中的id爲head的部分,值爲PlaceHolderMain的部分將會替換master page中id爲PlaceHolderMain的部分,這樣當咱們將Solution部署到SP中,並訪問index.aspx頁面的時候就會以test.master 爲整個頁面的master page。ui
經過以上步驟咱們便完成了對自定義的Sharepoint Master Page的建立和引用,但願以上內容對你們能有所幫助。this
例子代碼:spa
test.master設計
<%@Master language="C#"%>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE" />
<title>test</title>
</head>
<body>
<div>
This is Navigation
</div>
<div>
<asp:ContentPlaceHolder ID="PlaceHolderMain" runat="server">
</asp:ContentPlaceHolder>
</div>
<div>
This is Footer
</div>
</body>
</html>
複製代碼
Index.aspx:code
<%@ Page Language="C#" MasterPageFile="../../MasterPage/test.master" %>
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
this is index page
</asp:Content>
複製代碼
Sharepoint Solution部署到Sharepoint Server的路徑地址爲:orm
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS
部署的站點的訪問地址爲:
http://host/sites/reactapp/_layouts/15/+文件夾路徑