if HR is the audience.
GetAudience("HR") give access denied error.Use the following
using (SPSite site = new SPSite(SPContext.GetContext(Context).Site.ID))
{
ServerContext context = ServerContext.GetContext(site);
AudienceManager audManager = new AudienceManager(context);
SPUser user = SPControl.GetContextWeb(Context).CurrentUser;
foreach(Microsoft.Office.Server.Audience.Audience objAudience in audManager.Audiences)
{
if (objAudience != null && objAudience.AudienceName == "HR")
{
if (objAudience.IsMember(user.LoginName))
{
//Your code goes here
}
}
}
}
No comments:
Post a Comment