快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

和记娱乐网上官网:Sharepoint 70573考试习题和解析(Q4Q7)



Question 4

You have a Web Part that contains the following code seg和记娱乐网上官网ment. (Line numbers are included for reference only.)

01 protected void Page_Load(object sender, EventArgs e)

02 {

03SPSite site = new SPSite("http://www.contoso.com/default.aspx");

04{

05SPWeb web = site.OpenWeb();

06

07}

08 }

You deploy the Web Part to a SharePoint site.

After you deploy the Web Part, users report that the site loads slowly. You need to modify the Web Part to prevent the site from loading slowly.

What should you do?

A. Add the following line of code at line 06:

web.Close();

B. Add the following line of code at line 06:

web.Dispose();

C. Add the following line of code at line 06:

site.Close();

D. Change line 03 to the following code segment:

using (SPSite site = new SPSite("http://www.contoso.com/default.aspx"))

解析:

很显着,此题照样考的是SPSite,SPWeb工具内存的开释。

由前面Question2,3的阐发我们已经知道,应用Close措施与应用Dispose措施开释内存的差别。

显然谜底A,B,C只”分手” 开释了SPWeb工具或SPSite工具,而且开释的机会纰谬。

我们平日是经由过程两种要领来处置惩罚此类代码

1. Try….Catch….Finally代码布局来实现内存的开释处置惩罚,

2. 也可以经由过程using()语句来自动实现内存的开释(事实上,系统在运行时会自动把Using代码块处置惩罚为Try….Catch…Finally代码块)。

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

以是本题目精确选项应该是D

Question 5

You create an event receiver.

The ItemAdded method for the event receiver contains the following code segment. (Line numbers are included for reference only.)

01 SPWeb recWeb = properties.Web;

02 using (SPSite siteCollection = new SPSite("http://site1/hr"))

03 {

04using (SPWeb web = siteCollection.OpenWeb())

05{

06PublishingWeb oWeb = PublishingWeb.GetPublishingWeb(web);

07PublishingWebCollection pubWebs = oWeb.GetPublishingWebs();

08foreach (PublishingWeb iWeb in pubWebs)

09{

10try

11{

12SPFile page = web.GetFile("/Pages/default.aspx");

13SPLimitedWebPartManager wpManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);

14}

15finally

16{

17if (iWeb != null)

18{

19iWeb.Close();

20}

21}

22}

23}

24 }

You need to prevent the event receiver from causing memory leaks.

Which object should you dispose of?

A. oWeb at line 06

B. recWeb at line 01

C. wpManager at line 13

D. wpManager.Web at line 13

解析:

对付选项A. oWeb工具是经由过程PublishingWeb.GetPublishingWeb措施获取的,这个工具并不是SPWeb工具,它是一个包裹了SPWeb工具集的工具实例,我们可以经由过程此实例的GetPublishingWebs措施进一步获取这包裹于其内的SPWeb工具集。并且经由过程遍历这个工具集来分手开释其内的SPWeb工具,如下面代码:

using(SPWeb web = site.OpenWeb())

{PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);

PublishingWebCollection pubWebs = pubWe和记娱乐网上官网b.GetPublishingWebs());foreach(PublishingWeb innerPubWeb in pubWebs)

{try

{Process innerPubWeb

}finally

{innerPubWeb.Web.Dispose();

}}

}

而本题目也恰是经由过程上述要领来实现的,以是选项A不会造成内存透露。

对付选项B. recWeb是经由过程properties工具的Web属性获取的, properties是Evenreceiver的通报参数。如下例:

private static void ItemAdded(SPItemEventProperties properties)

{SPWeb web = properties.Web;

}

由此获取的SPWeb工具并不会造成内存的透露,由于它是由SPSite工具创建的,而此SPSite工具会在Event事故停止后自动被开释收受接收。

对付选项C,它并不是SPWeb工具,是以不存在要去开释它。

选项D为什么为造成内存透露问题呢,由于wpManager.Web是由page.GetLimitedWebPartManager措和记娱乐网上官网施返回的SPLimitedWebPartManager工具来获取的,这个SPLimitedWebPartManager工具实例包孕了对SPWeb工具的内部引用, 并且在引用SPWeb工具之后并不会自动开释它,以是,wpManager.Web工具是会造成内存透露的。换句话说:当我们应用GetLimitedWebPartManager相关措施来获取SPWeb工具时,必然要留意内存透露问题。

是以,本题应该选 D

参考 :

http://msdn.microsoft.com/zh-和记娱乐网上官网tw/library/ms497306.aspx

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/8999f361-6e8e-452a-a42e-c8bf323c106e

Question 6

You create a console application to manage Personal Sites.

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

01 SPSite siteCollection = new SPSite("http://moss");

02 UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(siteCollection));

03 UserProfile profile = profileManager.GetUserProfile("domain\username");

04 SPSite personalSite = profile.PersonalSite;

05

06 siteCollection.Dispose();

You deploy the application to a SharePoint site.

After deploying the application, users report that the site loads slowly. You need to modify the application to prevent the site from loading slowly.

What should you do?

A. Remove line 06.

B. Add the following line of code at line 05:

personalSite.close();

C. Add the following line of code at line 05:

personalSite.Dispose();

D. Change line 06 to the following code segment:

siteCollection.close();

解析:

选项A, 显然是错上加错,已经是因为SPSite造成的内存透露问题了,还在进一步扩大年夜这个问题。

选项 D. 显示无此需要,由于代码中已经有关于siteCollection的内存开释了,即:siteCollection.Dispose();

选项 B与C:Close措施在这里并不是真正的完成了开释,由于personalSite并不是你新New的一个SPSite工具实例,见Question2,3解析,以是只能经由过程 Dispose措施才能真正开释SPSite的内存。

以是本题目精确选项应该是C

Question 7

You are creating a Web Part for SharePoin和记娱乐网上官网t Server 2010.

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

01 protected override void CreateChildControls()

02 {

03base.CreateChildControls();

04SPSecurity.RunWithElevatedPrivileges(

05delegate()

06{

07Label ListCount = new Label();

08ListCount.Text = String.Format("There are {0} Lists", SPContext.Current.Web.Lists.Count);

09Controls.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

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: