title: Using ASPNet_Regiis to encrypt custom configuration section - can you do it?
body: <p>I have a web application with a custom configuration section.  That section contains information I'ld like to encrypt (was hoping to use ASPNet_RegIIS rather than do it myself).</p>
  
  <p>Web.Config:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
      &lt;configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"&gt;
        &lt;configSections&gt;
            &lt;section name="MyCustomSection" 
                     type="MyNamespace.MyCustomSectionHandler, MyAssembly"/&gt;
      &lt;/configSections&gt;
  &lt;configProtectedData&gt;
      &lt;providers&gt;
        &lt;clear /&gt;
        &lt;add name="DataProtectionConfigurationProvider"
             type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,
                     Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
                     processorArchitecture=MSIL"
             keyContainerName="MyKeyContainer"
             useMachineContainer="true" /&gt;
      &lt;/providers&gt;
    &lt;/configProtectedData&gt;
      &lt;MyCustomSection&gt;
         &lt;blah name="blah1"&gt;
            &lt;blahChild name="blah1Child1" /&gt;
         &lt;/blah&gt;
      &lt;/MyCustomSection&gt;
  </code></pre>
  
  <p>The configuration handler works great before trying to encrypt it.  When I try to encrypt it with:  </p>
  
  <blockquote>
    <p>aspnet_regiis -pef "MyCustomSection"
    c:\inetpub\wwwroot\MyWebsite -prov
    DataProtectionConfigurationProvider</p>
  </blockquote>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>Encrypting configuration section... An
    error occurred creating the
    configuration section handler for
    MyCustomSection: Could not load file
    or assembly 'MyAssembly' or one of its
    dependencies. The system cannot find
    the file specified.
    (c:\inetpub\wwwroot\MyWebsite\web.config
    line 5)</p>
  </blockquote>
  
  <p>I have tried with/without the provider configured.  With/without section groups.  With/Without having started the website before hand.  I've tried temporarily putting my assembly in the GAC for the registration.  I also tried my log4net section just to try something that wasn't mine, with no luck.  I've run the command prompt as Administrator.  Any ideas?  Or can ASPNet_RegIIS just not be used for custom sections?</p>
  
  <p>One final shot after viewing <a href="http://msdn.microsoft.com/en-us/library/system.configuration.iconfigurationsectionhandler.aspx" rel="noreferrer">MSDN</a> was changing my handler to inherit from ConfigurationSection rather than implementing IConfigurationSectionHandler since it was technically deprecated in 2.0 (hoping it was something regarding aspnet_regiis version).  No luck there either.</p>
  
  <p>Any ideas let me know.  Thanks!</p>