Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should be able to do it within a custom action. The catch that I've found is that loading an assembly for an ExeConfigurationFileMap will throw an exception, but you can handle that by adding an AssemblyResolve handler to the AppDomain. This is kind of a hack-up from a rich-client app I wrote to encrypt/decrypt protected configuration sections using a machine encryption key. It's probably not the prettiest code, but I'm hoping you can get the picture from it. This code assumes that you have the ProtectionProvider you want to use defined in the config file.</p> <pre><code>//class global static System.Reflection.Assembly DefiningAssembly; AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler); static System.Reflection.Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return DefiningAssembly; } </code></pre> <p>Then, you can load your configuration like this:</p> <pre><code>DefiningAssembly = System.Reflection.Assembly.LoadFrom("path to defining assembly for config"); //Set the Configuration using an ExeConfigurationFileMap - This works for any .config file. ExeConfigurationFileMap CfgMap = new ExeConfigurationFileMap(); CfgMap.ExeConfigFilename = "path to config file"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(CfgMap, ConfigurationUserLevel.None); List&lt;string&gt; DefiningAssemblyTypes = new List&lt;string&gt;(); foreach (System.Type type in DefiningAssembly.GetExportedTypes()) { DefiningAssemblyTypes.Add(type.Name); } foreach (ConfigurationSection tempSection in config.Sections) { if (DefiningAssemblyTypes.Contains(tempSection.ElementInformation.Type.Name)) { section = tempSection; break; } } ProtectionProviderName = section.SectionInformation.ProtectionProvider.Name; section.SectionInformation.ProtectSection(ProtectionProviderName); config.Save(ConfigurationSaveMode.Minimal, true); </code></pre> <p>I hope this helps you, best of luck.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload