Sharepoint习题——Sandboxed Solution

Question 7
You are creating a Web Part for SharePoint Server 2010.

The Web Part contains the following code segment. (Line numbers are included for reference only.)

01 protected override void CreateChildControls()
02 {
03   base.CreateChildControls();
04   SPSecurity.RunWithElevatedPrivileges(
05     delegate()
06     {
07       Label ListCount = new Label();
08       ListCount.Text = String.Format("There are {0} Lists", SPContext.Current.Web.Lists.Count);
09       Controls.Add(ListCount);
10     });
11 }

You need to identify which line of code prevents the Web Part from being deployed as a sandboxed solution.
Which line of code should you identify?
A.03
B. 04
C. 08
D. 09

解析
本题实质是考的关于Sandbox Solution的限制问题,Sandbox之所以安全,正是因为受限,所以它不支持通过RunWithElevatedPrivileges手段来提升代码的访问权限,因为如此一来就破坏了它的设计初衷。
Sandboxed solutions也不支持操作诸如下面的元素:
• Application Pages
• Custom Action Group
• Farm-scoped features
• HideCustomAction element
• Web Application-scoped features
• Workflows with code

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

 参考:

http://msdn.microsoft.com/en-us/library/gg615454(v=office.14).aspx

http://msdn.microsoft.com/en-us/library/gg615454.aspx

http://sharing-the-experience.blogspot.com.au/2011/06/sharepoint-2010-sandboxed-solution.html

Qeustion 8


You have a SharePoint site collection. The root Web of the site collection has the URL http://intranet.

You plan to create a user solution that will contain a Web Part. The Web Part will display the title of the root Web.

You write the following code segment for the Web Part. (Line numbers are included for reference only.)

01 SPSite currentSite = new SPSite("http://intranet");
02
03 Label currentTitle = new Label();
04 currentTitle.Text = currentSite.RootWeb.Title;

You add the Web Part to a page in the root Web and receive the following error message: "Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred."
You need to prevent the error from occurring.
What should you do?
A. Add the following line of code at line 02:
currentSite.OpenWeb();
B. Add the following line of code at line 02:
currentSite.OpenWeb("http://intranet");
C. Change line 01 to the following code segment:
SPSite currentSite = SPContext.Current.Site;
D. Change line 04 to the following code segment:
currentTitle.Text = currentSite.OpenWeb().Title;

解析:
 由报错信息” Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred”可以判断这个错误是由于Sandbox Solution在受限操作方面产生的问题。
  首先来看 A. B选项,它们都使用了OenWeb()方法,此方法是返回一个SPWeb对象,所以选项A, B在语法上都是错误的(左侧应该定义一个SPWeb变量来承接右边的方法返回值)。
  选项C. 有些人认为SPSite对象是不允许在Sandbox solution中使用的,这种认识不全对,实事上,我们可以在Sandbox Solution中使用SPSite对象,但前提是此SPSite对象”必须”位于”当前”的Site Collection中(也即:此Site Collection是位于当前的Context下的),所以,我们只能使用下面的语句来在Sandbox Solution中获取SPSite对象:
  SPSite currentSite = SPContext.Current.Site;
  如果要使用类似于本题目通过URL方式来获取SPSite,则并不能保持你提供的URL与Webpart在同一个Site Collection中,所以就很可能跳出上面的错误。
   选项 D.很明显,如果错误是由于在Sandbox Solution中获取SPSite对象的方法引起的,那么,选项D并不能解决这个错误。
所以本题目正确选项应该是C

参考:

http://social.msdn.microsoft.com/forums/en-US/sharepointgeneralprevious/thread/e84a457e-068c-465d-95f8-db56ac130cda
http://msdn.microsoft.com/en-us/library/ms473155.aspx

 

Question 9
You need to disable the CriticalExceptionCount measure for all user solutions.
You write the following code segment. (Line numbers are included for reference only.)
01 SPUserCodeService userCode = SPUserCodeService.Local;
02 SPResourceMeasureCollection measures = userCode.ResourceMeasures;
03 SPResourceMeasure measure = measures["CriticalExceptionCount"];
04
05 measure.Update();

Which code segment should you add at line 04?
A. measure.AbsoluteLimit = 0;
B. measure.AbsoluteLimit = 1;
C. measure.ResourcesPerPoint = 0;
D. measure.ResourcesPerPoint = 1;

解析:
本题目主要涉及到Sandbox Solution的资源配额管理,SharePoint 2010严格监控沙盒解决方案中的代码的运行状况。每个网站集均受可配置的日常资源点 的最大数目的限制。这些点基于某种专有算法进行累计,该算法会考虑网站集中安装的沙盒解决方案对 14 类资源的使用。当一个网站集超出其允许的最大点数(默认情况下,该数设置为 300)时,该网站集中的所有沙盒解决方案都将终止 (请注意:是此网站集中”所有”的沙盒解决方案),且在剩余时间内再也无法运行。
 
  SharePoint 包含14个方面的指标(Metric或者ResourceMeasure)来设置相应的使用配额
1. AbnormalProcessTerminationCount
2. CPUExecutionTime
3. CriticalExceptionCount
4. InvocationCount
5. PercentProcessorTime
6. ProcessCPUCycles
7. ProcessHandleCount
8. ProcessIOBytes
9. ProcessThreadCount
10. ProcessVirtualBytes
11. SharePointDatabaseQueryCount
12. SharePointDatabaseQueryTime
13. UnhandledExceptionCount
14. UnresponsiveprocessCount

本题提到的就是第3个指标:CriticalExceptionCount
上面的每个指标( ResourceMeasure)都包含有 ResourcesPerPoint 属性。 例如: AbnormalProcessTerminationCount 的 ResourcesPerPoint 值为 1。 每次发生了AbnormalProcessTermination错误(异常终止沙盒解决方案错误),则添加 1个 磅值。 如果想增加终止了沙盒解决方案罚点可以将 ResourcesPerPoint 设置为 2。 如果您不关心此统计数据,您可以使用 0。
上面的每一个指标还定义有一个AbsoluteLimit属性,此属性用于限制Sandbox Solution可消耗的此指标限制量, 比如,“UnhandledExceptionCount (ResourcesPerPoint: 50  AbsoluteLimit :3)” 表示:每50个未捕获异常将消耗1个“点数”,而每天如果某个解决方案包由于未捕获异常的原因消耗了3个“点数”(也就是它发生了150次异常未捕获的情况),那么这个沙盒解决方案包将被直接中止运行(请注音:是此沙盒解决方案),即使网站集当前还有剩余“点数”。如果不关心此统计数据,则可设置它的ResourcesPerPoint属性为0。
所以,AbsoluteLimit的值只会影响单个解决方案,这点不像每天最大使用率。这个两个级别的配额,每日的配额和绝对的限制,一起工作共同保护场的健康。
 有了上面的描述,再回到本题就很明确了,A.B首先排除,因为它们都只针对单个Sandbox Solution的限制,本题需要针对for all user solutions,所以只能是设置属性ResourcesPerPoint为0
  所以本题目正确选项应该是C

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值