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

The following code runs fine as an administrator but crashes with a 403 forbidden error when run as a non-admin on the am.GetAudience("My Audience") call. Can anyone spot why, I'm running with elevated privileges?

List<string> accounts = new List<string>();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite("http://mysite"))
    {
        AudienceManager am = new AudienceManager(ServerContext.GetContext(site));
        foreach (UserInfo member in am.GetAudience("My Audience").GetMembership())
        {
            accounts.Add(member.NTName.ToLower());
        }
    }
});
share|improve this question
    
bizarrly, using Audience a = am["My Audience"] works without elevating privileges.... –  user682 May 18 '10 at 8:56
    
I guess you mean am.Audiences["My Audience"]? This is because GetAudience calls an internal method CanAccess() that checks for UserProfileApplicationAdminRights and throws an UnauthorizedAccessException if you are not allowed to manage audiences. If you use the Audiences collection index remember to place the code inside a try/catch and catch the AudienceArgumentException to avoid the code to break if an audience does not exist. You see similar behaviour on User Profile Manager –  Anders Rask Oct 25 '11 at 8:31
add comment

1 Answer 1

Not that I have actually tried this, but I suspect the problem could be because the call to elevate priveliges only elevates up to the web application pool service account - this account may not have permission to access your SSP (which is where the audiences are managed).

share|improve this answer
add comment

Your Answer

 
discard

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