2

I'm using the following code to let users without full access rights on my site deleting it through a custom layouts page (delete site button):

  SPSecurity.RunWithElevatedPrivileges(delegate() {
         using (SPSite Site = SPContext.Current.Site) {
                 Site.AllowUnsafeUpdates = true;
                 Site.Delete();
                 Site.AllowUnsafeUpdates = false;
         }
        });

I get an access denied for the non site collection user trying to do this:

Deleting the site at http:// and not deleting AD accounts.
Unknown SPRequest error occurred. More information: 0x80070005
An SPRequest object was not disposed before the end of this thread.

5

You are passing a reference of the existing SPSite which also passes the current security context. Instead try:

  SPSecurity.RunWithElevatedPrivileges(delegate() {
         using (SPSite Site = new SPSite(SPContext.Current.Site.ID)) {
                 Site.AllowUnsafeUpdates = true;
                 Site.Delete();
                 Site.AllowUnsafeUpdates = false;
         }
        });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.