我已经建立了自定义成员资格和角色提供程序。用户是属于公司的一些客户,我使用公司作为角色。
我想创建 SharePoint Group 并向其中添加更多公司(例如行业类型),然后由 SPGroup 进行重定向和安全性。
如何检索当前登录用户的 SPGroup?
我想在我的自定义登录页面中这样做,所以另一个问题是如何在知道登录名的情况下检索 SPUser 或 SPGroup ?
这就是我现在所拥有的:
private List GetGroupsForUser(List roleAccounts)
{
List groups = new List();
SPSecurity.RunWithElevatedPrivileges(
delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
{
SPUserCollection users = site.RootWeb.SiteUsers;
foreach (string account in roleAccounts)
{
SPGroupCollection accGroups = users[account].Groups;
foreach (SPGroup spg in groups)
{
groups.Add(spg);
}
}
}
}
);
return groups;
}
private string GetRoleManagerName()
{
foreach (KeyValuePair setting in SPContext.Current.Site.WebApplication.IisSettings)
{
if (string.IsNullOrEmpty(setting.Value.RoleManager) == false)
return setting.Value.RoleManager.ToLower();
}
return null;
}
private List GetSpAccounts()
{
List roleAccounts = new List();
string roleProviderName = GetRoleManagerName();
foreach (string role in Roles.GetRolesForUser(login.UserName))
{
roleAccounts.Add(roleProviderName + ":" + role.ToLower());
}
return roleAccounts;
}
// and now I can use it
List roleAccounts = GetSpAccounts();
List groups = GetGroupsForUser(roleAccounts);
但是我有一种感觉,我不应该像这样手动执行此操作。如果只将角色添加到组中,目标受众将如何工作?