Runtime configuration changes for users without access config file

Topics: Enterprise Library Core, Logging Application Block
May 3, 2010 at 4:05 PM

How are runtime changes to the configuration of EntLib5 made if the user does not have access to PROG.exe.config? Our executables are XCopy deployed to a UNC path where the user will not have rights to update the file. Is there a way to change the configuration in memory?

System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.   at System.Security.AccessControl.Win32.SetSecurityInfo(ResourceType type, String name, SafeHandle handle, SecurityInfos securityInformation, SecurityIdentifier owner, SecurityIdentifier group, GenericAcl sacl, GenericAcl dacl)   at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object exceptionContext)
   at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections, Object exceptionContext)   at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections)   at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath)   at System.IO.File.SetAccessControl(String path, FileSecurity fileSecurity)   at System.Configuration.Internal.WriteFileContext.DuplicateTemplateAttributes(String source, String destination)   at System.Configuration.Internal.WriteFileContext.DuplicateFileAttributes(String source, String destination)   at System.Configuration.Internal.WriteFileContext.Complete(String filename, Boolean success)   at System.Configuration.Internal.InternalConfigHost.StaticWriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions)   at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext, Boolean assertPermissions)   at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext)   at System.Configuration.Internal.DelegatingConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext)   at System.Configuration.UpdateConfigHost.WriteCompleted(String streamName, Boolean success, Object writeContext)   at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)   at System.Configuration.Configuration.SaveAsImpl(String filename, ConfigurationSaveMode saveMode, Boolean forceSaveAll)   at System.Configuration.Configuration.Save()

May 4, 2010 at 4:24 PM
Edited May 4, 2010 at 4:26 PM

Personally, I don't know any way how to update the configuration in the memory and if there is any.

Though, here's a couple of options I have in mind that I'd hope would help. Either the administrator will have to go in after the install is complete and modify the file permissions manually to add a user group (for example "Everyone") to have Read/Write access to the file (this could be a security risk), or, you can possibly include a batch script or even another C# executable that will execute and modify the file post-installation.

 I'll update you once I found something better that would best addressed your problem.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

May 4, 2010 at 4:27 PM

That's what I figured. It wasn't difficult, but I went ahead and rolled my own logging facility and exception handling facility using Unity2 and only have App.config handle the wiring of Unity2. Default arguments to the logging and exception handling are done in the App.config and the rest is updated at runtime through service location and updating properties on the singletons. It is a bit disappointing to not have this flexibility in EntLib.

May 4, 2010 at 8:36 PM

If you're using 4.1 version or lower, you could build a DictionaryConfigurationSource.  Something like this - http://entlib.codeplex.com/wikipage?title=How%20do%20I%20use%20caching%20without%20the%20configuration%20file%3f&referringTitle=EntLib%20FAQ.

In version 5.0, this is much simpler and intuitive by using the Fluent Configuration API.  Check out the documentation (Developing Applications using Enterprise Library -> Configuring Enteprise Library -> Using the Fluent Configuration API).

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 8, 2010 at 10:24 PM

Hello,

I'm still tied to EntLib 1.1.  Is there any way to use the CacheManager witout modifying the configuration file?

Sep 8, 2010 at 11:09 PM

I posted my answer in your other thread.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 8, 2010 at 11:14 PM
Edited Sep 13, 2010 at 4:32 PM

Hi,


Thanks for the reply!

A download link to June2005 is  here:

http://www.microsoft.com/downloads/en/details.aspx?FamilyId=A7D2A109-660E-444E-945A-6B32AF1581B3&displaylang=en

From: AvanadeSupport [mailto:notifications@codeplex.com]
Sent: Wednesday, September 08, 2010 4:10 PM
To: Aaron Hudon
Subject: Re: Runtime configuration changes for users without access config file [entlib:211409]

 

From: AvanadeSupport

I posted my answer in your other thread.

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Read the full discussion online.

To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)

To start a new discussion for this project, email entlib@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Sep 9, 2010 at 12:23 AM
Edited Sep 9, 2010 at 1:34 AM

Unfortunately, I can't install that on my machine because I only have .NET Framework 3.5.  That version of Enterprise Library requires .NET Framework 1.1.   I would need to create a VM just so I could look at the source code.   I'll get back to you on this.

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 13, 2010 at 5:58 AM

Here's the equivalent code of that from the FAQ item:

ConfigurationDictionary configDictionary = new ConfigurationDictionary();
			
CacheManagerSettings cacheSettings = new CacheManagerSettings();
CacheStorageData storageConfig= new CustomCacheStorageData("MyStorage",  typeof(NullBackingStore).AssemblyQualifiedName);

CacheManagerData cacheManagerData = new CacheManagerData("CustomCache", 120, 100, 5, storageConfig);
cacheSettings.CacheManagers.Add(cacheManagerData);
cacheSettings.DefaultCacheManager = cacheManagerData.Name;

configDictionary.Add(CacheManagerSettings.SectionName, cacheSettings);
ConfigurationContext context = new ConfigurationContext(configDictionary);		    

CacheManagerFactory cacheFactory = new CacheManagerFactory(context);			
CacheManager cacheManager = cacheFactory.GetCacheManager();

 

Hope this helps.

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 13, 2010 at 4:33 PM

This works great w/ EntLib June2005.

Thanks for taking the time on this.