Sharepoint学习笔记—习题系列--70-573习题解析 -(Q66-Q69)

Question 66
You have a custom theme named MyTheme. The theme is defined in a file named MyTheme.thmx.
You have a console application that contains the following code segment. (Line numbers are included for reference only.)
01 using (SPSite site=new SPSite(“http://intranet”))
02 {
03   SPWeb web=site.OpenWeb();
04  
05 }
You need to programmatically apply the theme to a SharePoint site.
Which code segment should you add to the console application?
A. ThmxTheme.SetThemeUrlForWeb(web, "/_catalogs/theme/MyTheme.thmx", False);
B. web.AlternateCssUrl = "/_themes/MyTheme";
C. web.ApplyWebTemplate("MyTheme.thmx");
D. web.ThemedCssFolderUrl = "/_themes/MyTheme";

解析:
 本题想要做的事情就是通过代码去实现应用一个用户定义的主题。
 直接分析各选项:
选项A. ThmxTheme.SetThemeUrlForWeb(web, "/_catalogs/theme/MyTheme.thmx", False); SetThemeUrlForWeb 方法就是用来把主题应用到URL所指定的We上的。需要注意的是:如果那个Web已经应用了某个主题,且此主题不是共享的,那么此方法将会删除掉那个已经应用的主题。
SetThemeUrlForWeb方法定义如下:
public static void SetThemeUrlForWeb(
 SPWeb web,
 string themeUrl,
 bool shareGenerated
)

因此,选项A是本题答案。
选项B. web.AlternateCssUrl = "/_themes/MyTheme";本选项完成的是设置Web site的备用样式Alternate CSS (cascading style sheet)的URL路径。与设置主题Theme无关。
选项C. web.ApplyWebTemplate("MyTheme.thmx"); 本选项使用ApplyWebTemplate方法,此方法是用来设置site definition 或site template 的,所以,本选项参数都是错误的。
选项D. web.ThemedCssFolderUrl = "/_themes/MyTheme"; 本题的ThemedCssFolderUrl属性是用来设置包含了CSS文件的文件夹所在的URL,此CCS文件是被用在主题定义中的。 所以,它是关于文件路径的设置,而不是主题的设置。
所以本题目正确选项应该是A


参考:
http://msdn.microsoft.com/en-us/library/ee658324.aspx
http://msdn.microsoft.com/en-us/library/ff409648(v=office.14).aspx


Question 67
You plan to develop a Web Part that displays a SharePoint list.
The Web Part will verify the list permissions when users access by using the web.CurrentUser.DoesUserHavePermissions method.
You need to ensure that when users do not have permissions to the list, the Web Part displays the company's logo.
Which code segment should you add to the Web Part?
A. RunWithElevatedPrivileges
B. web.AllowUnsafeUpdates= true;
C. web.CurrentUser.RequireRequestToken = false;
D. web.ValidateFormDigest();


解析:
  本题是想在一个Webpart上展现List,并受权允许的用户访问此List,对无权访问的用户则只看得到公司的logo而看不到List。
  由于在题干中已经告知代码中采用了DoesUserHavePermissions 方法完成对用户访问权限的判定,所以问题的重点就不再是让你考虑如何去完成对用户访问权限的判定了,而是在权限判定之后如何操作才能得到题目所要求的显示效果。
  于是分析各备选项:
选项A. RunWithElevatedPrivileges特权提升是 Windows SharePoint Services 3.0 中增加的一项功能,使您能够使用更高的特权级别在代码中以编程方式执行操作。利用 SPSecurity.RunWithElevatedPrivileges 方法,您可以向在帐户上下文中运行一部分代码的委托提供高于当前用户的特权,通过这个方法,对于已经判定具有访问权限的用户,可以采用此方法去获取List的内容并显示出来。而对于没有访问权限的用户,则无限去取得数据库的内容并展现在List中。选项A是本题的正解。
选项B. web.AllowUnsafeUpdates= true; 此属性是用来标识是否允许更新数据库的。 通常而言SharePoint 2010 是要阻止开发人员对 GET 请求执行状态更改操作的。例如,在使用 GET 获取列表项或 Web 属性时,不允许 Microsoft ASP.NET 页更新列表项或 Web 属性的内容。但如果您的功能设计强制对 GET 请求执行状态更改操作,则您可通过将当前 Microsoft.SharePoint.SPWeb 类的 AllowUnsafeUpdates 属性设置为 true 以禁用此检查。请记住,在执行操作后重置该属性,并使用 try-catch-finally 块以确保异常不会将该属性保持为 true。因为此项存在安全隐患,所以,微软通常建议尽量避免使用 AllowUnsafeUpdates。就本题而言,本题不是操作List更新,而是操作List展现,所以此属性不是答案。
选项C. web.CurrentUser.RequireRequestToken = false; 此属性用来标识:SPUser对象是否需要Request token。它可以用在当你开发一个Sharepoint Web Part,此Web Part将用来承载Sharepoint 外部的应用程序时,就会用到此概念。例如:在Sharepoint 的Web Part中承载Microsoft Silverlight 应用程序。关于此方面的开发,微软称之为流体应用程序模型。如果有兴趣,你可以自己去找相关资料深入研究。对于本题而言,此属性不是用来控件List的内容显示与否的。

选项D. web.ValidateFormDigest(); 用于验证当前Request的Form Digest Control的。 此属性用于和“写入”相关的操作中的。根据微软的文档: 如果传递给 RunWithElevatedPrivileges 的方法包含任何写入操作,则调用 RunWithElevatedPrivileges 之前,应该调用 SPUtility.ValidateFormDigest() 或 SPWeb.ValidateFormDigest()。所以此方法也不是本题的答案。

所以本题目正确选项应该是A


参考:
http://www.shannonbray.com/2010/01/doesuserhavepermissions.html
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.allowunsafeupdates.aspx

 

Question 68
You create a Web Part that contains the following code segment. (Line numbers are included for reference only.)
01 public class WebPart1 : WebPart
02 {
03   public WebPart1() {}
04  
05   protected override void CreateChildControls()
06   {
07     Button clickButton = new Button();
08    
09     base.CreateChildControls();
10   }
11  
12   protected override void RenderContents(HtmlTextWriter writer)
13   {
14    
15     base.RenderContents(writer);
16   }
17 }
You discover that the clickButton button does not appear.
You need to ensure that clickButton appears.
What should you do?
A. Delete line 09.
B. Move line 07 to line 14.
C. Add the following line of code at line 08:
Controls.Add(clickButton);
D. Add the following line of code at line 08:
clickButton.Page = this.Page;

解析:
 本题是关于编写一个WebPart,想在其中呈现一个Button。
 本题没太多好讲的, 一般在aspx页面中,习惯上要动态加载控件是放在CreateChildControl()里面的,在里面创建Control然后用this.Controls.Add()来添加。本题重载了基类的CreateChildControl()方法,在自身的CreateChildControl()方法中实现添加控件到WebPart中。
 所以,选项A.B都破坏了CreateChildControl()方法功能结构。选项D则显得非常生僻,它仿佛是想把当前Page对象赋值给包含此Button控件的Page实例。为什么要这么做,就不得而知了。但不管如何,直接操作Button所属的Page与直接操作Button好像不太相关,所以,基于此判断,选项D也不该是本题的答案。
所以本题目正确选项应该是C


参考:
http://msdn.microsoft.com/en-us/library/ee231579.aspx
http://msdn.microsoft.com/en-us/library/ms476318(v=office.14).aspx
 
Question 69
You plan to create two Web Parts named Products and ProductDetails. You create an interface that contains the following code segment.
public interface Interface1
{
    string Productid { get; set; }
}
You need to ensure that the Products Web Part sends ProductId to the ProductDetails Web Part. You must achieve this goal by using the ASP.NET Web Part connection framework.
What should you do?
A. Implement Interface1 in the Products Web Part.
B. Implement Interface1 in the ProductDetails Web Part.
C. Add a private set-accessor-declaration to the Productid property.
D. Add a protected set-accessor-declaration to the Productid property.


解析:
 本题是想要基于ASP.NET Web Part connection framework在两个Web Part之间传递数据。从题目描述可知,Product部件是信息的提供方(Provider),ProductDetails部件是信息的用户方(Consumer)。
 一般的操作步骤是先创建 Web 部件连接接口(Interface),然后创建源 Web 部件(Provider),此Provider WebPart需要实现前面创建的接口。然后再创建目标 Web 部件(Consumer),此Consumber WebPart需要在其 CreateChildControls 子例程后插入 ConnectionConsumer 属性。这样可为 ConsumerWebPart Web 部件提供连接目标接口点。然后就可以部署并在Sharepoint UI上配置建立连接了。
 所以,从上面的描述我们就可以看到,本题题干部分建立了这个接口,然后在选项中,只有选项A是在Products Web Part实现此接口(因为Product部件是Provider方)。所以选项A就是本题答案。
  至于选项C.D都只是对Productid属性变量的访问限定,并不涉及Webpart连接接口的实现,所以不是本题的答案。
所以本题目正确选项应该是A


参考:

http://msdn.microsoft.com/zh-cn/library/ff597538(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/ms469765.aspx
http://johanolivier.blogspot.com/2010/08/sharepoint-2010-provider-consumer-web.html

 

posted @ 2013-07-19 12:44  wsdj  阅读(556)  评论(0编辑  收藏  举报