I am trying to find whether the current user is a member of a specific audience and used the below code however it returns "false" though the user belongs to the "testing" audience.
Microsoft.Office.Server.Audience.AudienceManager.IsCurrentUserInAudienceOf("Testing",false)
what would be the issue?
Update:
AIM:
We would like to redirect the user based on the audience group.
Eg.,
If Userx is a member of the audience "Testing", he will be redirected to "newWeb" otherwise to "oldWeb".
Implementation:
DelegationControl loads a user control, validation & redirection is taken place on the user control.
Update-2:
Tried the below code however getting the "Access denied" error message while trying to get the audience - "Audience audience = audienceManager.GetAudience("Testing");", have verified and found that the app., pool has full control on the user profile application.
else {
SPUser currentUser = SPControl.GetContextWeb(Context).CurrentUser;
SPSecurity.RunWithElevatedPrivileges(delegate
{
//HttpContext httpCtxt = HttpContext.Current;
//HttpContext.Current = null;
Microsoft.Office.Server.Audience.AudienceManager audienceManager = new
Microsoft.Office.Server.Audience.AudienceManager(SPServiceContext.Current);
Audience audience = audienceManager.GetAudience("Testing");
//HttpContext.Current = httpCtxt ;
if ( audience.IsMember(currentUser.LoginName))
{
Page.Response.Redirect("http://www.redirectNew.com");
}
else
{
Page.Response.Redirect("http://www.redirectOld.com");
}
});
}
