Question 57
You update a solution validator.
You need to ensure that all SharePoint solutions are validated the next time the solutions are executed.
What should you do?
A. Modify the Guid attribute of the solution validator.
B. Deactivate and activate all of the installed solutions.
C. Modify the Signature property of the solution validator.
D. In the Feature that deploys the solution validator, modify the Version attribute of the Feature element.

解析:
  本题题意是:你升级了一个Solution Validator 并想让它在你下一次运行Solution时生效,那么你该如何做呢?
   Sharepoint场管理员可以在场中部署Solution Validator,当向Solution Gallery中Upload某个Solution时,这些Validator就会运行。如果某个Solution没有通过Validation(即Validation Fail),那么这个Solution就不能被激活。如果一个Validator是在Solution被激活后才添加到场中的,那么这个Validator就会在Solution下一次被重新执行时被调用。如果一个Validator进行了升级,那么Solutions将会在下一次被重新执行时调用这个升级后的Validator。
我们通常通过编写一个继承自SPSolutionValidator(在命名空间namespace Microsoft.SharePoint.UserCode下) 的类来实现Solution Validator。一旦编写成功,我们还需要把它加入到SPUserCodeService SolutionValidators collection中,这一步通常需要我们编写一个Farm级别的Feature或使用PowerShell Script来完成。
如果要升级你的Solution Validator,你需要修改SPSolutionValidator.Signature属性,此属性存放的就是Solution Validator的版本号以及它的State Hash值。Solution Validator的构造函数将会使用到这个属性来构造Solution Validator。

下面是一段Solution Validator的实现代码

  1. [Guid("3014EB40-A067-4A21-BB83-B787229A7FC1")] //每个Validator都必须有一个唯一的Guid值以标识此Validator
  2. class WinsmartsSolutionValidator : SPSolutionValidator
  3. {
  4. private const string validatorName = "Winsmarts Solution Validator";
  5. public WinsmartsSolutionValidator() { }
  6. public WinsmartsSolutionValidator(SPUserCodeService userCodeService) //新建了一个构造函数以Override原来的构造函数
  7. : base(validatorName, userCodeService)
  8. {
  9. //在此构造函数中给Signature属性赋值
  10. this.Signature = ; //如果你要升级Validator,那么你就必须要修改Signature值
  11. }
  12. public override void ValidateSolution(SPSolutionValidationProperties properties)
  13. {
  14. base.ValidateSolution(properties);
  15. // 在此处写入Validator处理逻辑
  16. properties.Valid = false;
  17. properties.ValidationErrorMessage = "The uploaded solution is invalid";
  18. properties.ValidationErrorUrl = "/_layouts/SolutionValidator/WinsmartsErrorPage.aspx";
  19. }
  20. public override void ValidateAssembly(SPSolutionValidationProperties properties,
  21. SPSolutionFile assembly)
  22. {
  23. base.ValidateAssembly(properties, assembly);
  24. properties.Valid = true;
  25. }
  26. }

现在我们分析各个选项:
选项A. Guid 即SPSolutionValidator.ID,也即SPSolutionValidator的唯一标识名。此属性显然与Solution Validator的升级操作没直接关系,它只是一个标识。
选项B. Deactivate and activate all of the installed solutions.本选项所作的操作是停止和重启所有的Solution。此选项具有一定的迷惑性。事实上这是不需要的,正如我们上面所说,如果一个Validator进行了升级,那么Solutions将会在下一次被重新执行时调用这个升级后的Validator。请注意:是重新执行(excute),而不是重新激活(activate)。也就是说,Solution一直是处激活状态的,但它却不一定一直处于被执行的状态。
选项C. Signature property of the solution validator. 指的是SPSolutionValidator.Signature这个属性,此属性存放的就是Solution Validator的版本号以及它的State Hash值。
选项D. In the Feature that deploys the solution validator, modify the Version attribute of the Feature element. 选项D只是涉及到Feature的版本升级,而Solution Validator的升级必须要修改SPSolutionValidator.Signature属性。
所以本题目正确选项应该是C

参考:
http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.usercode.spsolutionvalidator.signature

Question 58
You are creating a Web Part. The Web Part will be used in a SharePoint subsite that has the URL http://www.contoso.com/hr.
You need to ensure that the Web Part activates a Feature in the subsite without causing a memory leak.
Which code segment should you use?
A. SPFeatureCollection featuresCollect = SPContext.Current.SiteFeatures;
featuresCollect.Add(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), true);
B. SPFeatureCollection featuresCollect = SPContext.Current.WebFeatures;
featuresCollect.Add(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), true);
C. SPSite web = new SPSite("http://www.contoso.com/hr");
SPFeatureCollection featureCollect = web.Features;
featureCollect.Add(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), true);
D. SPWeb web = new SPSite("http://www.contoso.com/hr").OpenWeb();
SPFeatureCollection featureCollect = web.Features;
featureCollect.Add(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), true);

解析:
 我们知道Feature是包括了 Microsoft SharePoint Foundation 中功能的一项或多项扩展的容器。功能包含 Feature.xml 文件和一个或多个元素文件。这些 XML 文件也称为功能定义。
   若干个功能聚合在一起就组成了功能集合,功能集合存储在 SPFeatureCollection 对象中。可通过使用 SPWebService、SPWebApplication、SPSite 和 SPWeb 对象的 Features 属性来访问 SPFeatureCollection。如果功能出现在集合中,则该功能已在指定的范围内激活。(此句就是选项A.B所做的事情:即声明一个SPFeatureCollection变量,然后对其赋值,选项A给featuresCollect赋予了Site(网站集)级别的功能集。选项B给featuresCollect赋予了Web(或subsite 即网站)级别的功能集。然后选项A.B再使用SPFeatureCollection类的Add方法添加一个新的Feature到这个功能集合对象中。所以指定的Feature被Add方法添加到对应的SPFeatureCollection功能集合对象中时,也就意味着此Feature在功能集合对象所对应的范围内被激活了,也即:选项A添加的Feature在网站集(Site)级别被激活,选项B添加的Feature则在网站(Web)级别被激活了。
   至于本题所要求的不要造成内存泄漏问题,这个是通过SPContext来实现的。因为在Sharepoint项目中,需要你关注的引起内存泄漏问题的对象通常是你在代码中Create的对象,至于SPContext它不是由你Create的,系统会自动对它进行Dispose。所以不会造成所谓的内存泄漏问题。如果你强行去Dispose此类不是由你Create的对象,反而会造成潜在的报错,例如报错:” Trying to use an SPWeb object that has been closed or disposed and is no longer valid.”
   所以,通过上面的分析,我们就可以认为选项B是本题的答案了。
   选项C. D是错误的用法,根据微软的文档描述,SPFeatureCollection的正确获取Features的方法应该是:
 “Use the SiteFeatures or WebFeatures property of the SPContext class to get the collection of activated Features for the current site collection or site.”  即:通过SPContext的SiteFeatures 或者WebFeatures属性来获取当前上下文中所激活的功能集。强调是要通过”当前上下文SPContext”去获取。而选项C.D则是试图从一个新创建的SPSite对象中获取
  而且选项C. D 中new SPSite("Absolute_URL")中的Absolute_URL使用的是Subsite的URL,而不是Site的URL,所以也会出错。
所以本题目正确选项应该是B

参考:
http://msdn.microsoft.com/zh-cn/library/ee537350(v=office.14).aspx
http://msdn.microsoft.com/zh-cn/library/ms466305(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontext.webfeatures.aspx
http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.spsite.aspx

Question 59
You create a Web Part that takes three values from three text boxes and creates a new SharePoint site when you click a button named CreateNewSite.
The Web Part contains the following code segment.
protected void CreateNewSite_Click(object sender, EventArgs e)
{
    SPSite site = SPContext.Current.Site;
    SPWeb web = site.AllWebs.Add(SiteNameTextBox.Text, SiteTitleTextBox.Text, SiteDescriptionTextBox.Text, 0, SPWebTemplate.WebTemplateSTS, false, false);
}

You test the Web Part and it works properly.
When another user attempts to use the Web Part to create a new site, he receives the following error message: "Error: Access Denied."
You need to ensure that users can use the Web Part to create new sites.
What should you do?
A. Add web.Update() after the code segment.
B. Add web.ValidatesFormDigest() after the code segment.
C. Run the code segment inside a SPSecurity.RunWithElevatedPrivileges delegate.
D. Add the following code after the code segment:
SPUser currentUser = System.web.CurrentUser;
web.Users.Add(currentUser.LoginName, currentUser.Email, currentUser.Name, "");

解析:
  本题描述那么多,其实就是说想通过用户点击Button来创建一个Site,而创建Site时需要相应的参数,这些参数从Text Box中获取,也即参数值由用户输入。
遇到的主要问题是:一个用户创建成功(说明代码在实现功能上没有问题),而另一个用户则遇到了”Access Denied”报错。所以,很显然,本题的答案就在于解决”Access Denied”报错上。
   根据报错信息,可以很容易判断这是一个由于操作权限不足引起的错误。所以解决问题的方法理所当然的集中在如何获取足够的权限上。
   分别分析各选项:
选项A. web.Update()实现的是把对Web Site的更改写入到对应的数据库中,完成的是对SPWeb对象的更新。所以与本题无关(本题是想新创建一个SPWeb)。
选项B. Add web.ValidatesFormDigest()方法。我们知道: 出于安全考虑,默认情况下,Microsoft SharePoint Foundation 不允许从 Web 应用程序进行发布以修改数据库内容(如List内容,List的内容当然是保存在内容数据库Content Database里的),除非请求页上包括安全验证。Sharepoint可以通过在请求页上添加页面指令和 FormDigest 控件来更新单个网站或网站集的数据。在 ASPX 页上插入此控件会生成安全验证或消息摘要,以帮助防止在用户因被骗而发布数据到服务器时产生的攻击。安全验证特定于用户、网站和时间段,并在可配置的时间段后过期。当用户请求页时,服务器返回插入了安全验证的页。当用户随后提交表单时,服务器会验证安全验证是否更改。 而本选项的web.ValidatesFormDigest()方法就是用来Validate此页面上的FormDigest 控件的。 FormDigest问题针对的是整个页面,而不是针对不同的用户。所以,本选项与权限提升无关。
选项C. Run the code segment inside a SPSecurity.RunWithElevatedPrivileges delegate. 这正是用来提升用户权限的工具。一般情况下我们使用VS2010开发工具开发的SharePoint项目,在部署到服务器上之后都会以当前账户来运行编写的代码所调用的资源。但是又一种情况发生了,SharePoint2010中有许多的网站、列表、文档库等资源,但并不是每个当前用户都是可以访问到的。例如:一个存储每个员工薪资的列表,这个列表肯定不会让公司内所有人员都能看到的,只能让少部分人去访问,但是如果在开发的一段代码中调用了这个列表的资源,而当前登录系统的这个账户却不能访问这个列表,因此如果这个账户运行了这段代码,就会得到一个禁止访问的错误信息。为了解决这样的问题,我们可以采取权限提升的方法强制这段代码以”管理员账户身份”运行。需要注意的 SPSecurity. RunWithElevatedPrivileges的运行必需在一个新的上下文中执行,意思是说必需要New一个新的SPSite与SPWeb才可以。
所以此选项就是本题的答案。
选项D. 完成的是添加一个新的SPUser到Web中,很显然这种操作与提升权限没有关联。
所以本题目正确选项应该是C

参考:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.spweb_methods(v=office.12).aspx

Sharepoint学习笔记—习题系列--70-573习题解析 -(Q57-Q59)的更多相关文章

  1. Sharepoint学习笔记—ECM系列—文档列表的Metedata Navigation与Key Filter功能的实现

    如果一个文档列表中存放了成百上千的文档,想要快速的找到你想要的还真不是件容易的事,Sharepoint提供了Metedata Navigation与Key Filter功能可以帮助我们快速的过滤和定位 ...

  2. Sharepoint学习笔记—ECM系列--文档集(Document Set)的实现

    文档集是 SharePoint Server 2010 中的一项新功能,它使组织能够管理单个可交付文档或工作产品(可包含多个文档或文件).文档集是特殊类型的文件夹,它合并了唯一的文档集属性以及文件夹和 ...

  3. Sharepoint学习笔记—习题系列--70-576习题解析 --索引目录

        Sharepoint学习笔记—习题系列--70-576习题解析  为便于查阅,这里整理并列出了70-576习题解析系列的所有问题,有些内容可能会在以后更新. 需要事先申明的是:     1. ...

  4. Sharepoint学习笔记—习题系列--70-573习题解析 --索引目录

                  Sharepoint学习笔记—习题系列--70-573习题解析 为便于查阅,这里整理并列出了我前面播客中的关于70-573习题解析系列的所有问题,有些内容可能会在以后更新, ...

  5. Deep Learning(深度学习)学习笔记整理系列之(五)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  6. Deep Learning(深度学习)学习笔记整理系列之(八)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  7. Deep Learning(深度学习)学习笔记整理系列之(七)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  8. Deep Learning(深度学习)学习笔记整理系列之(六)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  9. Deep Learning(深度学习)学习笔记整理系列之(四)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  10. Deep Learning(深度学习)学习笔记整理系列之(三)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

随机推荐

  1. p2p研究

    p2p网络结构 中央集中式结构 无集中式非结构 混合式以超级节点结构 穿透原理 防火墙为克隆型(cone net),对称型(Symmetric NAT) 只有克隆型才能用打洞方式穿透 开源方案 htt ...

  2. 【转载】Solr4+IKAnalyzer的安装配置

    转载:http://www.cnblogs.com/madyina/p/4131751.html 一.下载Solr4.10.2 我们以Windows版本为例,solr-4.10.2.zip是目前最新版 ...

  3. oracle/sqlserver 递归

    1.Oracle递归查询 2.SqlServer递归查询 with cte as ( select t.id,t.name,t.parentId from dbo.Department t where ...

  4. CentOS linux系统搭建LAMP环境

    准备工作: 1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/iptables-A INPUT -m state –state NEW -m tcp -p tcp –dpo ...

  5. 初探KMP算法

            数据结构上老师也没讲这个,平常ACM比赛时我也没怎么理解,只是背会了代码--前天在博客园上看见了一篇介绍KMP的,不经意间就勾起了我的回忆,写下来吧,记得更牢. 一.理论准备      ...

  6. 记第二次使用php开发项目之绝不重复自己

    严格说起来,自己并非一个合格的php程序员.第一次使用php开发,不过是因为游戏上线,需要一个统计管理后台和GM后台,因为招聘已经来不及,所以我就上前线了! 凭着对php语法的一点点记忆(大学的时候学 ...

  7. JS魔法堂:doctype我们应该了解的基础知识

    一.前言 什么是doctype?其实我们一直使用,却很少停下来看清楚它到底是什么,对网页有什么作用.本篇将和大家一起探讨那个默默无闻的doctype吧! 二.什么是doctype doctype或DT ...

  8. Struts 2常用的Ajax标签

    Struts 2对Ajax的支持 •Struts 2对Ajax提供了很好的支持 –Struts 2.1提供了基于Dojo的Ajax标签,对Ajax操作进行了进步封装,可以更快捷容易的使用Ajax   ...

  9. 迭代接口的IEnumerator

    我们经常在工作中用到对List,Dictionary对象的Foreach遍历,取出每一项. 其实这个接口很简单,只有一个属性2个方法. [ComVisible(true), Guid("49 ...

  10. 【C#】线程之Parallel

    在一些常见的编程情形中,使用任务也许能提升性能.为了简化变成,静态类System.Threading.Tasks.Parallel封装了这些常见的情形,它内部使用Task对象. Parallel.Fo ...