nerdexam
Microsoft

70-573 · Question #40

You create a Web Part that queries a list. The Web Part contains the following code segment. (Line numbers are included for reference only.) 01 protected override void Render( HtmlTextWriter writer)…

The correct answer is A. SPSecurity.RunWithElevatedPrivileges(delegate(). MNEMONIC RULE: "UnauthorizedAccessException = RunWithElevatedPrivileges = Answer A is the only one that will give us a SystemAccount token from within RunWithElevatedPrivilegesstatement. That's what we are trying to get in case UnauthorizedAccessException occurs.

Developing SharePoint Solutions

Question

You create a Web Part that queries a list. The Web Part contains the following code segment. (Line numbers are included for reference only.) 01 protected override void Render( HtmlTextWriter writer) 02 { 03 SPUserToken spInToken = GetTheContext ( SPContext.Current.Site ) ; 04 using (SPSite aSite = nera SPSite ( curSiteCtx.ID , spInToken ) ) 05 { 06 07 } 08 } 09 private SPUserToken GetTheContext ( SPSite nUeb ) 10 < 11 nWeb.CatchAccessDeniedException = false; 12 SPUserToken spToken = null; 13 try 14 { 15 spToken = nWeb.SystemAccount.UserToken ; 16 } 17 catch ( UnauthorizedAccessException ) 18 { 19 20 } 21 return spToken; 22 } You need to ensure that users without permissions to the list can view the contents of the list from the Web Part. Which code segment should you add at line 19?

Options

  • ASPSecurity.RunWithElevatedPrivileges(delegate()
  • BSPSecurity.RunWithElevatedPrivileges(delegate()
  • CspToken = nWeb.RootWeb.AllUsers[SPContext.Current.Web.Name].UserToken;
  • DspToken =

How the community answered

(37 responses)
  • A
    73% (27)
  • B
    16% (6)
  • C
    3% (1)
  • D
    8% (3)

Explanation

MNEMONIC RULE: "UnauthorizedAccessException = RunWithElevatedPrivileges = Answer A is the only one that will give us a SystemAccount token from within RunWithElevatedPrivilegesstatement. That's what we are trying to get in case UnauthorizedAccessException occurs.

Topics

#elevated privileges#SPSecurity#SPUserToken#RunWithElevatedPrivileges

Community Discussion

No community discussion yet for this question.

Full 70-573 Practice