tags:

views:

16

answers:

1

Hi all

I have a custom form that lists the site groups and the users in each group.

the form has twi drop down lists: one to display the site's group and the other to display the users in that group.

when I log to the form with the administrator user it works fine.

But if I log in with a user with manage hierarchy permission level, it omly displays the info of the domain groups and if I try to access a sharepoint group I get an access denied error.

I use run with elevated permissions in my code

I really don't know what to do in this

thanks.

A: 

Two common mistakes when using RunWithElevatedPrivileges is:

  1. Using the SPContext.Current.Web (or Site etc) won't change the identity of the web object, it is already in memory.

  2. Declaring the SPWeb outside the delegate, with similar results of mistake 1

That said, try something like:

Guid siteId = SPContext.Current.Site.Id;

SPSecurity.RunWithElevatedPrivileges(() => 
using (SPSite elevatedSite = new SPSite(siteId))
using (SPWeb elevatedWeb = elevatedSite.RootWeb)
{
   //impl
});
F.Aquino