Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Try using this:

AudienceManager.IsCurrentUserInAudienceOf("Some",false)

http://msdn.microsoft.com/en-us/library/ms582323.aspx

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.