nerdexam
Microsoft

70-573 · Question #11

You create a Web Part that takes three values from three text boxes and creates a new SharePoint site when you click a button named CreateNewSite. The Web Part contains the following code segment…

The correct answer is C. Run the code segment inside a SPSecurity.RunWithElevatedPrivileges delegate. MNEMONIC RULE: "Access Denied = RunWithElevatedPrivileges" SPSecurity.RunWithElevatedPrivileges Method us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

Developing Business Logic

Question

You create a Web Part that takes three values from three text boxes and creates a new SharePoint site when you click a button named CreateNewSite. The Web Part contains the following code segment. protected void CreateNewSite_Click(object sender, EventArgs e) { SPSite site = SPContext.Current.Site; SPWeb web = site.AllWebs.Add(SiteNameTextBox.Text, SiteTitleTextBox.Text, SiteDescriptionTextBox.Text, 0, SPWebTemplate.WebTemplateSTS, false, false); } You test the Web Part and it works properly. When another user attempts to use the Web Part to create a new site, he receives the following error message: "Error: Access Denied." You need to ensure that users can use the Web Part to create new sites. What should you do?

Options

  • AAdd web.Update() after the code segment.
  • BAdd web.ValidatesFormDigest() after the code segment.
  • CRun the code segment inside a SPSecurity.RunWithElevatedPrivileges delegate.
  • DAdd the following code after the code segment:

How the community answered

(16 responses)
  • A
    6% (1)
  • B
    13% (2)
  • C
    75% (12)
  • D
    6% (1)

Explanation

MNEMONIC RULE: "Access Denied = RunWithElevatedPrivileges" SPSecurity.RunWithElevatedPrivileges Method us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

Topics

#elevated privileges#SPSecurity#RunWithElevatedPrivileges#permission error

Community Discussion

No community discussion yet for this question.

Full 70-573 Practice