nerdexam
Microsoft

70-573 · Question #278

You create a Web Part that programmatically updates the description of the current SharePoint site. The Web Part contains the following code segment. (Line numbers are included for reference only.)…

The correct answer is C. Change lines 10 and 11 to use the eWeb variable. MNEMONIC RULE: "eWeb" The inner using statement works with eWeb object, so we should use eWeb object all along.

Developing SharePoint Solutions

Question

You create a Web Part that programmatically updates the description of the current SharePoint site. The Web Part contains the following code segment. (Line numbers are included for reference only.) 01 SPSecurity.RunWithElevatedPrivileges(delegate() 02 { 03 SPSite currSite = SPContext.Current.Site; 04 SPWeb currWeb = SPContext.Current.Web; 05 using (SPSite eSite = new SPSite(currSite.ID)) 06 { 07 using (SPWeb eWeb = eSite.OpenWeb(currWeb.ID)) 08 { 09 eWeb.AllowUnsafeUpdates = true; 10 currWeb.Description = "Test"; 11 currWeb.Update(); 12 eWeb.AllowUnsafeUpdates = false; 13 } 14 } 15 }); Users report that they receive an Access Denied error message when they use the Web Part. You need to ensure that all users can use the Web Part to update the description of the current site. What should you do?

Options

  • ARemove lines 09 and 12.
  • BRemove lines 10 and 11.
  • CChange lines 10 and 11 to use the eWeb variable.
  • DChange lines 09 and 12 to use the currWeb variable.

How the community answered

(55 responses)
  • A
    7% (4)
  • B
    15% (8)
  • C
    75% (41)
  • D
    4% (2)

Explanation

MNEMONIC RULE: "eWeb" The inner using statement works with eWeb object, so we should use eWeb object all along.

Topics

#RunWithElevatedPrivileges#SPWeb#elevated context#security

Community Discussion

No community discussion yet for this question.

Full 70-573 Practice