Tuesday, March 25, 2008

Access Denied on AudienceGlobal.CanAccess()

So I'm using the AudienceManager's GetAudience() and it blows access denied error, even when using RunWithElevatedPrivileges. I spent time looking for the root of the problem and as far as I can get is "AudienceGlobal.CanAccess(this.m_serverContext);"
which is the first line of code in the GetAudience method.

This is all withen: Microsoft.Office.Server.Audience.AudienceManager.GetAudience

I found one other reference on the web linked here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2978930&SiteID=1

The solution provided is a work-around and I was able to use it.

foreach (Microsoft.Office.Server.Audience.Audience objAudience in audienceManager.Audiences)
{
if (objAudience != null && objAudience.AudienceName == audienceName)
{
//use objAudience just as if you had called GetAudience
}
}