I am trying to do some things in a web part based on the audience that a user is in. This is my first pass at the code, and it works on my dev VM. However on the test machine it fails blocking access to the page with a 403 Forbidden error. The line that it baulks at is the GetAudience line. I suppose that the user does not have permissions to see the audience list or something...
var site = SPControl.GetContextSite(Context);
var context = ServerContext.GetContext(site);
var audienceManager = new AudienceManager(context);
var audience = audienceManager.GetAudience("Some");
var user = SPControl.GetContextWeb(Context).CurrentUser;
if (audience.IsMember(user.LoginName)) {
// user is in "some" audience, lets do stuff specific to that audience
}
How SHOULD I be tasting a user to get the audience membership?