Which code segment should you add at line 13?

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?

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?

A.
SPSecurity.RunWithElevatedPrivileges(EvelvatedSub) Private Sub ElevatedSub() Using eSite
As New SPSite(nWeb.ID) spToken = nWeb.SystemAccount.UserToken End Using End Sub

B.
SPSecurity.RunWithElevatedPrivileges(EvelvatedSub) Private Sub ElevatedSub() Using eSite
As New SPSite(nWeb.ID) spToken = SPContext.Current.Web.CurrentUser.UserToken End Using
End Sub

C.
spToken = nWeb.RootWeb.AllUsers(SPContext.Current.Web.Name).UserToken

D.
spToken = nWeb.RootWeb.AllUsers(SPContext.Current.Web.Name).UserToken



Leave a Reply 0

Your email address will not be published. Required fields are marked *