Encrypting / decrypting web.config sections

  1. Determine the identity of your ASP.NET application. In most situations this will be the “NT AUTHORITYNETWORK SERVICE” account.
  2. Grant the account determined in step 1 access to the machine-level RSA key container:
    aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT AUTHORITYNETWORK SERVICE"
  3. To encrypt your appSettings section execute the following command:
    aspnet_regiis -pe "appSettings" -app "/Site"
    appSettings is casesensitive and /Site point to the virtual folder where your web.config is stored.
  4. To decrypt the web.config section execute the following command:
    aspnet_regiis–pd "appSettings" –app "/Site"
  5. Retrieving your encrypted settings can be done with the ConfigurationManager:
    string username = ConfigurationManager.AppSettings["username"].ToString();
    
Share

Leave a Reply

Your email address will not be published. Required fields are marked *