[SP logger] access denied when saving areas

Nov 23, 2011 at 7:52 AM

Hello

As the title indicates i'm having problems with an access denied exception whenever i try to add or remove my areas with the logger. Specifically when i call "configuredAreas.SaveConfiguration();" from FeatureActivated() or FeatureDeactivating(). The rest of the cody is copy pasted from the SPG2010 so I don't think the problem is there. The only addition i made is I call EnsureRegisteredAsEventSource in the Feature installed method.

The funny thing is it worked a day ago :/ and I have no idea what went wrong.

I am quite lost on what to do and any help would be appreciated...

Coordinator
Nov 23, 2011 at 12:03 PM

Did you change the account the timer job is running under, or permissions for that account?  It sounds like the account the event receiver is running under doesn't have permissions to write to farm level configuration. 

Nov 24, 2011 at 6:49 AM
Edited Nov 24, 2011 at 6:52 AM

Checked the "Sharepoint 2010 Timer" service and it's running as Network Service user... so I think that's OK.

 

P.S.: the code i'm using in the event reciever

// This helper property builds a collection of areas and categories.
        DiagnosticsAreaCollection _myAreas = null;
        DiagnosticsAreaCollection MyAreas
        {
            get
            {
                if (_myAreas == null)
                {
                    _myAreas = new DiagnosticsAreaCollection();
                    DiagnosticsArea crmArea = new DiagnosticsArea("PorocilniSistem");
                    crmArea.DiagnosticsCategories.Add(new DiagnosticsCategory(
                    "KreiranjePDFporocil", EventSeverity.Warning, TraceSeverity.Medium));
                    _myAreas.Add(crmArea);
                }
                return _myAreas;
            }
        }
        
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            IConfigManager configMgr = SharePointServiceLocator.GetCurrent().GetInstance<IConfigManager>();
            DiagnosticsAreaCollection configuredAreas = new DiagnosticsAreaCollection(configMgr);
            foreach (DiagnosticsArea newArea in MyAreas)
            {
                var existingArea = configuredAreas[newArea.Name];
                if (existingArea == null)
                {
                    configuredAreas.Add(newArea);
                }
                else
                {
                    foreach (DiagnosticsCategory c in newArea.DiagnosticsCategories)
                    {
                        var existingCategory = existingArea.DiagnosticsCategories[c.Name];
                        if (existingCategory == null)
                        {
                            existingArea.DiagnosticsCategories.Add(c);
                        }
                    }
                }
            }
            configuredAreas.SaveConfiguration();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            IConfigManager configMgr = SharePointServiceLocator.GetCurrent().GetInstance<IConfigManager>();
            DiagnosticsAreaCollection configuredAreas = new DiagnosticsAreaCollection(configMgr);
            foreach (DiagnosticsArea area in MyAreas)
            {
                DiagnosticsArea areaToRemove = configuredAreas[area.Name];
                if (areaToRemove != null)
                {
                    foreach (DiagnosticsCategory c in area.DiagnosticsCategories)
                    {
                        var existingCat = areaToRemove.DiagnosticsCategories[c.Name];
                        if (existingCat != null)
                        {
                            areaToRemove.DiagnosticsCategories.Remove(existingCat);
                        }
                    }

                    if (areaToRemove.DiagnosticsCategories.Count == 0)
                    {
                        configuredAreas.Remove(areaToRemove);
                    }
                }
            }
            configuredAreas.SaveConfiguration();
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            DiagnosticsAreaEventSource.EnsureConfiguredAreasRegistered();
        }

Nov 24, 2011 at 7:29 AM

Went through the ULS logs and found this:

The SPPersistedObject, FarmSettingStore Name=_pnpFarmConfig_, could not be updated because the current user is not a Farm Administrator.

Feature receiver assembly 'KreiranjePDFporocil, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd534680f0521697', class 'KreiranjePDFporocil.Features.KreirajPDFporocilaFeature.KreirajPDFporocilaFeatureEventReceiver', method 'FeatureActivated' for feature '06d55510-5328-47d7-a3a6-59d1d860d924' threw an exception: Microsoft.Practices.SharePoint.Common.Configuration.ConfigurationException: Configsetting with key 'Microsoft.Practices.SharePoint.DiagnosticAreas' could not be set 'Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsAreaCollection' with type 'Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsAreaCollection'. The technical exception was: System.Security.SecurityException: Dostop zavrnjen. ---> System.Security.SecurityException: Dostop zavrnjen.   
 at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()   
 at Microsoft.Practices.SharePoint.Common.Configuration.SPFarmPropertyBag.set_Item(String key, String value)   
 at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(String key, Object value, IPropertyBag propertyBag)  The Zone of the assembly that failed was:  MyComputer     -
 -- End of inner exception stack trace ---   
 at Microsoft.Practices.SharePoint.Common.Configuration.ConfigManager.SetInPropertyBag(String key, Object value, IPropertyBag propertyBag)   
 at Microsoft.Practices.SharePoint.Common.Logging.DiagnosticsAreaCollection.SaveConfiguration()   
 at KreiranjePDFporocil.Features.KreirajPDFporocilaFeature.KreirajPDFporocilaFeatureEventReceiver.FeatureActivated(SPFeatureReceiverProperties properties)   
 at Microsoft.SharePoint.SPFeature.DoActivationCallout(Boolean fActivate, Boolean fForce)

And am even more confused at what could be wrong.

Nov 25, 2011 at 7:30 AM

Solved the issue with a script from here http://unclepaul84.blogspot.com/2010/06/sppersistedobject-xxxxxxxxxxx-could-not.html. Essentially you change Microsoft.SharePoint.Administration.SPWebService.ContentService.RemoteAdministratorAccessDenied to FALSE.

 

Cheers