Im trying to run the code below but I get a UnauthorizedAccessException
at the last line(using SP 2013)
TaxonomySession newTaxonomySession = new TaxonomySession(site);
var termStore = newTaxonomySession.DefaultSiteCollectionTermStore;
var siteCollectionGroup = termStore.GetSiteCollectionGroup(site);// <-- throws UnauthorizedAccessException
- I have wrapped the code in
RunWithElevatedPrivileges
- User xxx is farm admin
- Added user xxx to Managed Metadata admin in CA, also as Term Store administrators, Group Manager for the term group and owner of term set
- I am logged in as xxx and also tried to impersonate xxx (new
SPSite
(url, userToken)) - I am able to activate feature in SP GUI without problems
- I Have verified through logging that the
web.CurrentUser.LoginName
is xxx - I have also tried to set
HttpContext.Current = null
Before the code above
Details:
I'm stapling the feature to SPSPERS
Template (my sites-sitecoll), so the feature receiver code (above) is run when a new personal site coll. is created.