nerdexam
Microsoft

70-573 · Question #112

You create a Web Part that queries a list. The Web Part contains the following code segment. (Line numbers are included for reference only.) 01Protected Overloads Overrides Sub Render(ByVal writer…

The correct answer is A. SPSecurity.RunWithElevatedPrivileges(EvelvatedSub). See the full explanation below for the reasoning.

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.) 01Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter) 02 Dim spInToken As SPUserToken = GetTheContext(SPContext.Current.Site) 03 Using aSite As New SPSite(curSiteCtx.ID, spInToken) 04 ... 05 End Using 06 End Sub 07Private Function GetTheContext(ByVal nWeb As SPSite) As SPUserToken 08 nWeb.CatchAccessDeniedException = False 09 Dim spToken As SPUserToken = Nothing 10 Try 11 spToken = nWeb.SystemAccount.UserToken 12 Catch generatedExceptionName As UnauthorizedAccessException 13 14 End Try 15 Return spToken 16End Function 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 13?

Options

  • ASPSecurity.RunWithElevatedPrivileges(EvelvatedSub)
  • BSPSecurity.RunWithElevatedPrivileges(EvelvatedSub)
  • CspToken = nWeb.RootWeb.AllUsers(SPContext.Current.Web.Name).UserToken
  • DspToken = nWeb.RootWeb.AllUsers(SPContext.Current.Web.Name).UserToken

How the community answered

(46 responses)
  • A
    74% (34)
  • B
    9% (4)
  • C
    4% (2)
  • D
    13% (6)

Community Discussion

No community discussion yet for this question.

Full 70-573 Practice