70-573 · Question #279
You create a Web Part. You need to display the number of visits to a SharePoint site collection in a label named LblVisits. You write the following code segment. (Line numbers are included for…
The correct answer is A. SPSite site = new SPSite(SPContext.Current.Site.ID). MNEMONIC RULE: "new SPSite" You must create new objects inside the delegate if you need to execute the members of the objects withelevated privileges. SPSecurity.RunWithElevatedPrivileges Method…
Question
You create a Web Part. You need to display the number of visits to a SharePoint site collection in a label named LblVisits. You write the following code segment. (Line numbers are included for reference only.) 01 SPSecurity.RunWithElevatedPrivileges(delegate() 02 { 03 try 04 { 05 06 LblVisits.Text = site.Usage.Visits.ToString(); 07 } 08 finally 09 { 10 11 } 12 }); Which code segment should you add at line 05?
Options
- ASPSite site = new SPSite(SPContext.Current.Site.ID);
- BSPSite site = SPContext.Current.Site;
- CSPSite site = SPContext.GetContext(HttpContext.Current).Site;
- DSPSite site = SPControl.GetContextSite(HttpContext.Current);
How the community answered
(33 responses)- A76% (25)
- B3% (1)
- C15% (5)
- D6% (2)
Explanation
MNEMONIC RULE: "new SPSite" You must create new objects inside the delegate if you need to execute the members of the objects withelevated privileges. SPSecurity.RunWithElevatedPrivileges Method us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges(v=office.14).aspx
Topics
Community Discussion
No community discussion yet for this question.