Hi everybody I cannot execute the code inside
SPSecurity.RunWithElevatedPrivileges any ideas about this
this is function where i get all toles related to each user in group the
problem in debug the code inside spsecurity.RunwithElevatedPrivilages
doesn't Execute, and when i remove this line it return to me access denied
for users
public bool IsUserAuthorized(SPUser user, string roleName)
{
bool flagForRoles = true;
SPRoleAssignment RoleAss = null;
Guid siteId = SPContext.Current.Site.ID;
Guid webId = SPContext.Current.Web.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//put your code here to get the group and test for the user
using(SPSite site=new SPSite(siteId))
{
using (SPWeb web = site.OpenWeb(webId))
{
SPGroupCollection groupcoll = user.Groups;
foreach (SPGroup group in groupcoll)
{
RoleAss =
web.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal)group);
foreach (SPRoleDefinition RoleDef in
RoleAss.RoleDefinitionBindings)
{
if (string.Equals(RoleDef.Name, "Contribute"))
{
flagForRoles = false;
break;
}
else if(string.Equals(RoleDef.Name,roleName))
{
flagForRoles=true;
break;
}
}
}
web.Dispose();
site.Dispose();
}
}
});
return flagForRoles;
}
No comments:
Post a Comment