Sharepoint习题——master page

Question23
You have a SharePoint site. The current master page of the site is v4.master.
You create a custom master page named MyMasterPage.master.
You deploy the master page to /_catalogs/masterpage/.
You need to apply the custom master page to only the content pages of the site.
What should you do?
A. Rename the custom master page as v4.master and overwrite /_catalogs/masterpage/v4.master.
B. Rename the custom master page as v4.master and overwrite \14\TEMPLATE\GLOBAL\v4.master.
C. Set the MasterUrl property and CustomMasterUrl property of the site to /_catalogs/masterpage/MyMasterPage.master.
D. In the @Page directive of each page layout, set the MasterPageFile attribute to /_catalogs/masterpage/MyMasterPage.master.

解析:
 本题的意图就是把某个Site的Content Pages(内容页)的母板页设置为用户自定义的母板页。
 下面我们逐一讲解:
一、首先是了解Sharepoint的页面类型:
 Microsoft SharePoint Foundation 中主要有两种类型的页面,分别是应用程序页(Application Page) 和网站页(Site Page)。
   应用程序页(Application Page) 和网站页(Site Page)都从同一母版页继承其布局。
   应用程序页(Application Page)与传统的 Microsoft ASP.NET 3.5 网页最为相似。但是,应用程序页面并非直接派生自System.Web.UI.Page,而是派生自 LayoutsPageBase 或 UnsecuredLayoutsPageBase。
   网站页(Site Page)是由最终用户创建、编辑和自定义的页面,是可以由用户个性化定制与修改的页面。网站页是通过存储在前端 Web 服务器(Front-End Web Server)的文件系统上的模板页面设置的。在设置网站时,SharePoint Foundation 会创建指向文件系统上的页面模板实例的指针,这个指针存放在使用了此网站页的Website的Content Database中。这样,SharePoint Foundation 就可以避免重复创建每次创建网站时都要设置的页面的副本。
而本题所说的Content Pages(内容页)就是我们上面所说的Site Pages.
二、了解v4.master母板页
SharePoint2010  Foundation 使用 v4.master 作为其主要母版页。所有内容页(Content Pages)和应用程序页(Application pages)都使用 v4.master。
安装该产品后,母版页位于 %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\GLOBAL 目录中(即:本题的选项B 所示路径: \14\TEMPLATE\GLOBAL\v4.master )。
如果针对特定 SharePoint Foundation 网站编辑该母版页,则编辑后的母版页文件副本将存储在内容数据库中(即:本题的选项A:  /_catalogs/masterpage/  此路径就是一个virtual path, 存在于内容数据库[Content Database]中, 而不是存在于文件系统中。也即, 修改后的V4.master就存放在Masterpage Gallery中,你可以使用SharePoint Designer来把修改后的V4.master存放到这里。)
 所以选项A与选项B对于本题并无实质的区别,它们之间的区别就是存放位置的不同,产生的方式不同。它们的共同点就是都使用了V4.master,而按照上面的描述,V4.master是对”所有”的内容和应用程序页都适用。但本题要求的是只针对某个Site内的Content Page(内容页)。
所以使用和修改V4.master显然不符合本题的要求,因为它的影响范围不仅仅针对Content Pages还针对了Application Pages。因此,选项A. B直接可以排除掉了。
   三、内容页是如何引用母板页的
Windows SharePoint Services 提供了若干个用于引用母版页的令牌:
两个动态令牌("~masterurl/default.master" 和 "~masterurl/custom.master")
两个静态令牌("~site/default.master" 和 "~sitecollection/default.master")。

•动态令牌 "~masterurl/default.master"
此令牌使用 MasterPageFile 属性 (attribute) 和 MasterUrl 属性 (property) 的值从内容页引用母版页。例如,在页指令 <%@ Page MasterPageFile="~masterurl\default.master"%> 中,令牌 "~masterurl/default.master" 在运行时将替换为 MasterUrl 属性 (property) 中的值。此属性 (property) 包含母版页相对于服务器的完整路径(包含文件名)。
安装时,所有 SharePoint 内容页都使用此动态令牌并且 MasterUrl 属性 (property) 设置为 Windows SharePoint Services default.master;但是,您可以随时更改此值以指向不同的母版页。
重要提示: 整个字符串 "~masterurl/default.master" 均包含该令牌。

•动态令牌 "~masterurl/custom.master"
此令牌使用 MasterPageFile 属性 (attribute) 和 CustomMasterUrl 属性 (property) 的值从内容页引用母版页。令牌 "~masterurl/custom.master" 在运行时将替换为 CustomMasterUrl 属性 (property) 的值,此属性包含母版页的相对于服务器的完整路径(包含文件名)。
默认情况下,任何 SharePoint 内容页均不使用此令牌,且此令牌仅作为具有另一个共享母版页的一种方式提供。
重要提示: 整个字符串 "~masterurl/custom.master" 均包含该令牌。

•静态令牌 "~site/default.master" 和 "~sitecollection/default.master"
您可以使用这些令牌链接到相对于网站或网站集的母版页。例如,如果您的内容页位于 http://siteColl/subsite1/subsite2/default.aspx 中,并且您使用令牌 "~sitecollection/mypage.master",则内容页将使用位于 http://siteColl/mypage.master 中的母版页。如果您使用令牌 "~site/mypage.master",则内容页将使用位于 http://siteColl/subsite1/subsite2/mypage.master 中的母版页。

注意:默认情况下,MasterUrl 和 CustomMasterUrl 属性均设置为“/ _catalogs/masterpage/default.master”。如果您随后需要删除 default.master,则必须将这两个属性均设置为其他值(而不是只设置其中的一个),否则会引发一个错误,指出该 default.master 文件仍被用作该网站的母版页。(这属于选项C的知识了)

此外,您还可以通过直接更改在页指令中指定的 MasterPageFile 属性 (attribute) 的 URL,来更改内容页所使用的母版页。但与使用 MasterUrl 属性 (property) 更改母版页不同的是,它是对网页内容的更改。
有了上面的描述,我们就可以回过头来分析选项D与C了
  选项D. 即是指 Content Page中的 <% @Page MasterPageFile="/_catalogs/masterpage/MyMasterPage.master" %> 设置,很明显这种设置是不符合上面四种令牌中的任何一种使用规范的, MasterPageFile属性的设置值应该使用上述的令牌规范,例如: <% @Page MasterPageFile="~masterurl/default.master" %>  ,即一定要要内容页中使用”令牌”来引用母板页。
另外需要注意的是 在Sharepoint2010中,如果要设置应用程序页的母板页,则已经不再这样使用MasterPageFile,而是用DynamicMasterPageFile属性来代替,当然,这点对于本题是题外话。
  选项 C. 根据上面的注意点:默认情况下,MasterUrl 和 CustomMasterUrl 属性均设置为“/ _catalogs/masterpage/default.master”。如果您随后需要删除 default.master,则必须将这两个属性均设置为其他值(而不是只设置其中的一个),而且在Content Page中的 <% @Page MasterPageFile 属性的设置保持了默认的令牌,所以此修改是生效的。
   所以本题目正确选项应该是C

参考:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.masterurl.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.custommasterurl.aspx
http://msdn.microsoft.com/en-au/library/ee537576(v=office.14).aspx
http://www.cnblogs.com/sunjunlin/archive/2010/09/18/1830468.html
http://blogs.msdn.com/b/bgeoffro/archive/2009/06/22/master-pages-revisited-references-to-master-pages-in-sharepoint.aspx
http://msdn.microsoft.com/zh-cn/library/ms476046.aspx
http://msdn.microsoft.com/zh-cn/library/ee537530(v=office.14).aspx
http://office.microsoft.com/en-us/sharepoint-designer-help/create-a-content-page-from-a-master-page-HA010167218.aspx

 

Question 24
You have a custom master page named MyApplication.master.
You need to apply MyApplication.master to only a custom application page in a SharePoint site. You must achieve the goal by using the minimum amount of effort.
What should you do?
A. Add a custom HTTP module to the Web application that modifies the master page.
B. Add a custom HTTP module to the Web application that modifies the custom application page.
C. Set the MasterPageFile attribute to ~/_layouts/MyApplication.master in the @Page directive of the custom application page.
D. Rename the custom application page as application.master and overwrite the default application.master page in the 14\TEMPLATE\LAYOUTS folder.

解析:
  本题与Question23对应,Question23是修改”内容页”的母板页,而本题则是修改”应用程序页”的母板页。而且是修改custom application page(用户自定义应用程序页)的母板页。并且:要求用最少的工作量实现目的。

  在Sharepoin中应用程序页引用母板页有3种情况:
  1. 在 Microsoft SharePoint Foundation 中,应用程序页现在可以通过 DynamicMasterPageFile 属性继承自定义的网站母版页。所谓DynamicMasterPageFile属性就是用于代替MasterPageFile属性的。
  通过使用 DynamicMasterPageFile 属性,应用程序页可引用网站母版页,而不是默认的应用程序母版页。如果需要,网站管理员可以通过管理中心或使用 SPWebApplication 对象的 MasterPageReferenceEnabled 属性,来禁止自动引用网站母版页。
  2. 针对某此需要安全保护的应用程序页, 如果这些页面在加载动态母版页时遇到问题,将改为加载 _layouts 文件夹中的安全母版页。例如:
• AccessDenied.aspx
• MngSiteAdmin.aspx
• People.aspx
• RecycleBin.aspx
• ReGhost.aspx
• ReqAcc.aspx
• Settings.aspx
• UserDisp.aspx
• ViewLsts.aspx
3. 在自定义应用程序页上使用动态母版页
如果创建自定义应用程序页,则页面必须继承自 LayoutsPageBase 基类,并且”必须”使用下面列出的动态标记之一。
动态标记:
•~masterurl/default.master – 应用程序页引用存储在 MasterUrl 属性中的母版页文件。
•~masterurl/custom.master – 应用程序页引用存储在 CustomMasterUrl 属性中的母版页文件。
  并且更为重要的是:不能在 DynamicMasterPageFile 属性中使用静态标记。
 
对于A. 通过HTTP module来修改母板页也是一种途径,实事上在普通的ASP.NET网站中,我们也可以通过此技术来实现母板页的修改,但对于Sharepoint平台而言,采用此技术则需要更多的步骤,最直接的首先要实现如何注入Preinit事件,然后还要再处理MasterPageFile属性的不同情况,以指向不同的MasterPage。但针对本题,此选项显然不能说是“最简单”的途径。
对于B. 通过HTTP module来修改应用程序页显然是怎么也达不到修改母板页的目的的。
选项D. 本选项的做法就是把应用程序页命名为母板页并覆盖原有的母板页,此方法只能用混乱来形容了。实事上,在Sharepoint2013中,借助设计管理器,您可以将 .html 文件转换为 SharePoint 2013 母版页(.master 文件)。转换后,HTML 文件和母版页相关联,因此在您编辑并保存 HTML 文件后,这些更改内容会同步到关联母版页中。但也只是针对html文件而非应用程序页(aspx页面)。

选项C. 本选项对于本题应该是“相对正确”的答案,为什么这样说呢?因为实际上此方法并不适用于Sharepoint2010,正如我们上面的知识点所述,Sharepoint2010使用了DynamicMasterPageFile属性代替MasterPageFile属性,并且当在自定义应用程序页上使用动态母版页时,不能在 DynamicMasterPageFile 属性中使用静态标记。但针对Sharepoint2007,选项C的方法又的确是生效的。

所以本题目正确选项只能是C

参考:
 http://msdn.microsoft.com/zh-cn/library/ee537530(v=office.14).aspx
http://kjellsj.blogspot.com.au/2010/07/using-page-specific-master-page-in.html
http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/369fe1ac-5611-4889-b714-5ecbe3b7e6d5
http://spdailytips.blogspot.com.au/2012/06/change-master-page-on-fly-using.html
http://www.codeproject.com/Articles/43377/SharePoint-Dynamically-Change-Master-Page

 

Question25
You develop a new publishing page layout named MyPage.aspx for a SharePoint site.
You create an Elements.xml file.

Elements.xml contains the following code segment. (Line numbers are included for reference only.)
01 <File Url="mypage.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
02 <Property Name="Title" Value="MyPage" />
03 <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
04 <Property Name="PublishingAssociatedContentType" Value="; 05 #$Resources:cmscore,contenttype_page_name;;
06 #0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE811;#"/>
07
08 </File>
You need to prevent users from creating pages based on the page layout.
Which property tag should you add at line 07?

A. <Property Name="Hidden" Value="True" />
B. <Property Name="PublishingHidden" Value="True" />
C. <Property Name="RequireSiteAdministrator" Value="False" />
D. <Property Name="Rights" Value="ViewListItems" />

解析:
 本题的要求就是禁用你创建的页面布局MyPage.aspx。
页面布局(Page Layout) 是一个模板,将其与母版页结合使用可控制页面的外观和内容。每个页面布局都有一个关联的内容类型,该内容类型决定可存储在基于页面布局的页面上的内容类型。
  默认情况下,SharePoint Server 2010 将创建每个网站的母版页样式库;但是,只能使用网站集(Site Collection)的首要网站(Top level site)的母版页样式库(Master Page Gallery)中所存储的页面布局来创建新的页面。
   创建页面布局时,会创建一个 SharePoint 使用的 .aspx 文件(即本题中的MyPage.aspx),并且会向该页面布局的 HTML 版本添加一些 HTML 标记。
   在用VS2010创建一个页面布局时,我们可以清楚地看到其Element.xml的组织结构.如下示例代码

复制代码
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="PageLayoutsModule"
          Url="_catalogs/masterpage">
    <File Path="PageLayoutsModule\TermsPageLayout.aspx"
          Url="TermsPageLayout.aspx"
          Type="GhostableInLibrary">
      <Property Name="ContentType"                Value="$Resources:cmscore,contenttype_pagelayout_name;"/>
      <Property Name="PublishingAssociatedContentType"
                Value=";#TermsAndConditionsType;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390035e07eba31844ff5bd10e36808ad5efd;#"/>
      <Property Name="Title"
                Value="Terms and Conditions Page"/>
    </File>
  </Module>
</Elements>
复制代码

即Element下套着Module元素,Module元素下套着File元素,File元素下套着Property元素。
本例就是要在Page Layout 这种Content Type所有应该具有的Property (或Internal Field)中寻找答案。(所有的Page Layouts必须继承自"Page Layout" content type,我们在上述Elements.xml的代码中用Resource file 值来指定:<Property Name="ContentType"                Value="$Resources:cmscore,contenttype_pagelayout_name;"/>)。

选项A.  Hidden,此属性是Content Type Class所具备的属性,表示此Content Type是否允许在用户界面直接创建或使用。它影响到Create Content Type 时的Page,而不是Create 一个Page Layout时的Page。
选项B. PublishingHidden,通过设置此属性,我们能够实现在Create Page页面所提供的可使用的Page Layout列表中,隐藏特定的Page Layout。这正是我们本题想要的功能。所以也是本题的答案。此属于也适用 于母版页隐藏。

选项C. RequireSiteAdministrator, 此属性是LayoutsPageBase类所具备的属性,用于标识是否只允许site collection administrators (网站集管理员)访问此页面。所以本选项也是不对的。
选项D.  ViewListItems属于Microsoft.SharePoint程序集下的SPBasePermissions 枚举值,属于Sharepoint权限管理的一部分,比如用于RoleDefinition的设置定义。本题此处的ViewListItems是指允许查看ListItem.不条例本题要求。
所以本题目正确选项应该是B

http://msdn.microsoft.com/zh-cn/library/ms544928(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/ms459213.aspx
http://msdn.microsoft.com/en-us/library/ms462994.aspx
http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.client.contenttype_properties.aspx
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopmentprevious/thread/45e1782a-dbe7-4513-bafd-e84de61dfe7d http://community.bamboosolutions.com/blogs/sharepoint-2010/archive/2011/11/23/sharepoint-2010-cookbook-how-to-create-custom-page-layout-for-publishing-site-using-visual-studio-2010.aspx
 

Question26
You have a SharePoint site collection. The default master page for the site collection displays a navigation bar on the left side of the page.
You create a custom content page.
You need to hide the navigation bar on only the custom content page.
What should you do?
A. On the default master page, remove the ContentPlaceHolder control that has the ID PlaceHolderLeftNavBar.
B. On the default master page, set the Visible attribute to False in the ContentPlaceHolder control that has the ID PlaceHolderLeftNavBar.
C. Add an empty Content control to the custom content page and set the ContentPlaceHolderID attribute to PlaceHolderLeftNavBar.
D. Add a Content control to the custom content page, set the ContentPlaceHolderID attribute to PlaceHolderLeftNavBar, and set the Visible attribute to False.

解析:
本题的意思是要隐藏特定用户内容页面上的导航条(此导航条属于此内容页面所属的母板页的一部分),且仅针对此特定内容页面。
 光从题意就首先可以排除A.B选项了,因为它们都是基于Master page做修改,而所有针对Master Page的修改必须影响到所有调用此Master Page的页面。
 所以问题集中到了选项C与D。我们可以通过在特定页面上放置Content Control来覆盖掉在Master Page定义的相应ContentPlaceHolder Control,这种修改是个性化的,它只影响到被修改的Content Page本身。
具有迷惑性是选项D,它所作的操作是在你的Content Page上放置 Content Control并命名为你想要覆盖的ContentPlaceHolder Control的ID,失败就发生在你设置了它的Visible属性,当你设置此属性为False时,Sharepoint根本就不会Render此部分的内容,那么你想要Override位于Master Page上的对应的ContentPlaceHolder Control的意图就完全落空了。(事实是:你可以在Master Page中找到ContentPlaceHolder Control,通过设置它的Visible属性为False或者移到某个不可见的区域来达到隐藏此控件的目的,但这样的修改必然会影响到所有引用此母板页的页面)。
所以本题目正确选项应该是C :通过放置一个空的Content Control来实现既覆盖又不显示的双重目的。

参考:
http://www.sdtimes.com/SHARE_POINTERS_USING_A_PAGE_LAYOUT_TO_HIDE_THE_LEFT_NAVIGATION/By_Ryan_Keller/33596
http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.contentplaceholder.aspx


Question 27
You develop a custom master page.
You need to ensure that all pages that use the master page contain a specific image.
Page developers must be able to change the image on individual pages. The master page must be compatible with the default content page.
What should you add to the master page?
A. a ContentPlaceHolder control
B. a Delegate control
C. a PlaceHolder control
D. an HTML Div element

解析:
 本题要求是:1.开发人员可以在各个不同的页面上修改”镶嵌”于母板页上的图片。2. 修改图片之后,内容页与母板页不会发生冲突。
 它考的其实就是ContentPlaceHolder(占位符),
Sharepoint母版页包含显示在所有页上的静态文本和控件,还包含一个或多个 ContentPlaceholder 控件。内容占位符定义内容页中存储的信息的显示区域。自定义母版页必须与默认母版页具有相同的控件和内容占位符。
在 Microsoft SharePoint Foundation 中,应用程序和内容页的内容占位符现在是相同的。通过使用相同的内容占位符,内容和应用程序页可以使用相同的母版页,以便在整个网站中获得更一致的外观。
根据本题题意:
 1.你想要使此图片最初作用到所有引用母板页的页面,所以就必须在母板页中放置存放图片的占位符。
 2.你想对某些页面作个性修改,则只需要在这些页面再放置Content Control并命名为你想要覆盖的那个存放图片的ContentPlaceHolder就行了。
 3.所谓内容页与母板页在个性化修改后不会发生冲突,就是指你不能在作了个性化修改后,再去删除或修改母板页上的这个ContentPlaceHolder。
 因此本题答案是 A.
 选项B. 委托控制提供了一种指定特定功能的候选控件的方法,并为这些控件选择功能提供程序。Sharepoint的Delegate Control就像一个容器,它封装了各种默认的控件在里面。这些控件可以被用户开发的自定义控件进行替换,从而达到用户自定义的功能和效果。
   SharePoint 提供了不少的delegate controls:
    •AdditionalPageHead
    •GlobalSiteLink0
    •GlobalSiteLink1
    •GlobalSiteLink2
    •PublishingConsole
    •QuickLaunchDataSource
    •SmallSearchInputBox
    •TopNavigationDataSource
上面所列举的Delegate controls可以在运行时被用户自定义的控件或Feature动态替换。所以很明显,基于Delegate control的实现必需至少要已经有对应的Control在母板页上存在,而且也不可能在每个引用此母板页的页面上个性化再定义自己的Control,因此,选项B不对。
选项C. PlaceHolder Control这是普通ASP.NET网站技术的概念。基本思路就是先放置一个空的容器(an empty container control)在页面上,然后在运行时动态地加载此容器内的子元素。 实现思路和ContentPlaceHolder一致,但不属于Sharepoint的技术内容。
D. an HTML Div element 就完全是定制化了,根本做不到母板页与引用页面的融合。
所以本题目正确选项应该是A

参考:
http://msdn.microsoft.com/zh-cn/library/ee537576(v=office.14).aspx
http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.contentplaceholder.aspx
http://msdn.microsoft.com/zh-cn/library/ms478826.aspx
http://www.cnblogs.com/wsdj-ITtech/archive/2011/11/26/2263041.html
http://msdn.microsoft.com/zh-cn/library/tety77hf(v=vs.71).aspx

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值