Question

nikhil j1 on Thu, 04 Oct 2012 18:05:59


am trying to retrive users from owners group.

grp = SPContext.Current.Web.Groups.GetByID();
usrColl = grp.Users;
foreach (SPUser usr in usrColl)

after comming to the foeach loop (usrColl) am getting access Denined error.
am using runwithelevatedprevilages for the above code and current logged in user was added to memebers group.

any idea what can be the problem ?

Thx


Sponsored



Replies

Anand . Ramanan on Thu, 04 Oct 2012 18:11:19


You have to reopen the web object after elevating privileges.  the SPContext web is already created and secured based on the currently logged in user so wrapping the current context web into a elevated code block does not changed the permissions applied to it.

GUID id = SPContext.Current.Web.ID

elevatedcode
{

using(SPSite site = new SPSite(id))
{
  using(SPWeb web = site.OpenWeb())
  {
     //access groups
  }
}

}

Anand