title: Web.Config file encrypt not working after publishing
body: <p>I encrypted the <code>web.config</code> file using following code</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      EncriptSection("connectionStrings", "DataProtectionConfigurationProvider");
  }
  private void EncriptSection(string sectionName, string provider)
  {
      Configuration config =
           WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
      ConfigurationSection section = config.GetSection(sectionName);
      if (section != null &amp;&amp; !section.SectionInformation.IsProtected)
      {
          section.SectionInformation.ProtectSection(provider);
          config.Save();
      }
  }
  </code></pre>
  
  <p>after encryption web.config file,Site is running good in local system but when i publish my site and deployed into server.</p>
  
  <p>Pages are not reading  the <code>web.config</code> file and giving error.When I decrypt the file and then publish the site into server site is running good on server.</p>
  
  <p>How can i encrypt the file and run it into server.</p>
  
  <pre><code>Below is the error which i am getting now :
  </code></pre>
  
  <p><strong>Runtime Error</strong></p>
  
  <p>Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. </p>
  
  <p>Details: To enable the details of this specific error message to be viewable on remote machines, please create a <code>&lt;customErrors&gt;</code> tag within a <code>web.config</code> configuration file located in the root directory of the current web application. This <code>&lt;customErrors&gt;</code> tag should then have its <code>mode</code> attribute set to <code>Off</code>.</p>
  
  <pre><code>&lt;!-- Web.Config Configuration File --&gt;
  
  &lt;configuration&gt;
      &lt;system.web&gt;
          &lt;customErrors mode="Off"/&gt;
      &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Notes: The current error page you are seeing can be replaced by a custom error page by modifying the <code>defaultRedirect</code> attribute of the application's <code>&lt;customErrors&gt;</code> configuration tag to point to a custom error page URL.</p>
  
  <pre><code>&lt;!-- Web.Config Configuration File --&gt;
  
  &lt;configuration&gt;
      &lt;system.web&gt;
          &lt;customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/&gt;
      &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>****AFTER WHEN I PUT** </p>
  
  <pre><code>&lt;customErrors mode="Off"/&gt; 
  </code></pre>
  
  <p>**in configuartion then get following error****</p>
  
  <blockquote>
    <p>Parser Error Message: Failed to decrypt using provider
    'DataProtectionConfigurationProvider'. Error message from the
    provider: Key not valid for use in specified state. (Exception from
    HRESULT: 0x8009000B)</p>
  </blockquote>
  
  <p>Source Error: </p>
  
  <pre><code>Line 13:  &lt;/system.web&gt;
  Line 14:   &lt;connectionStrings  
                   configProtectionProvider="DataProtectionConfigurationProvider"&gt;
  Line 15:     &lt;EncryptedData&gt;
  Line 16:     &lt;CipherData&gt;
  Line 17:    &lt;CipherValue&gt;reertertertreterterterterterterterte
                rtertertertertert5345345345 &lt;/CipherValue&gt;
  </code></pre>
  
  <p>Source File: C:\FOLDER\web.config    Line: 15 </p>