2
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
        {
            foreach (SPWeb oWeb in oSite.RootWeb.GetSubwebsForCurrentUser())
            {
                permission = string.Empty;
                foreach (SPGroup group in oWeb.Groups)
                {
                    foreach (SPUser u in group.Users)
                    {
                        if (u.Name == (userName))
                        {
                            foreach (SPRole role in u.Roles)
                            {
                                permission += role.Name.ToString() + ", ";
                            }
                                                       }
                    } // Taking All Permission details of user
                }
                permission = " [" + permission.TrimEnd(", ".ToCharArray()) + "]";
            }
        }

我的最终字符串变量将具有类似[Read, Visitor][Read]或的值[visitor, Read]

我想拥有所有权限名称,实际上我在 u.Roles [Roles is absolute now] 上收到错误/警告,

SPRoleDefination通过使用等 帮助我获得许可SPRoleDefinitionCollectionroleDefinitions = oWeb.RoleDefinitions; SPRoleDefinitionroleDefinition

谢谢普拉文

4

1 回答 1

0

试试这个

 foreach (SPWeb oWeb in oSite.RootWeb.GetSubwebsForCurrentUser())
            {

                SPRoleDefinitionCollection oCollection= oWeb.RoleDefinitions;

                foreach (SPRoleDefinition r in oCollection)
                {
                    SPRoleDefinition roleDef = oCollection[r.Name.ToString()];

                    foreach (SPRoleAssignment oAssigment in oWeb.RoleAssignments)
                    {
                        if (oAssigment.RoleDefinitionBindings.Contains(roleDef))
                        {
                            permissions+= r.Name.ToString();
                        }
                    }

                }
于 2013-07-31T18:17:52.797 回答