Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Configure It Out with the Configuration Management Application Block : Page 4

Nearly every application needs some way to configure itself so that it can interact with a given environment. For the simplest applications, app.config or machine.config probably meet your needs. For more complex applications you probably need something a bit more robust, secure, and scalable—and that's when you need to explore the Configuration Management Application Block.


advertisement
Adding a Custom Configuration Section
Now that the custom configuration declarations have been added, the next step is to add the custom configuration section. Again looking at Figure 2, you can see the custom configuration section <applicationConfigurationManagement>. Notice that the element name matches the first custom configuration declaration section's attribute name; this is because the custom configuration declaration section defines a class and assembly used to parse the specified custom configuration section.

Add the <appicationConfigurationManagement> XML element to the <configuration> XML element. Next, add a new XML element called <configSection> with an attribute called name. The value of the name attribute should correspond with the name attribute in the custom configuration declaration section element that defines which configuration section handler to use.

How many times has the Configuration Settings Fairy changed production settings without your knowledge?
Looking at the application configuration file in Listing 1, the value is myConfig. The <configSection> element can have up to three child XML elements:

  • The <configCache> that handles the caching settings
  • The <configProvider> that handles the settings for the Configuration Storage Provider (CSP)
  • The <protectionProvider> that handles the settings for the Data Protection Provider (DPP)
The <configCache> element contains two attributes: one called enabled that can be set to true or false, and the other called refresh. For more details on how to set the refresh attribute's value, look at the section Caching Data later in this article. The example application configuration file in Listing 1 has the cache feature enabled and set to refresh every 15 minutes.

The <configProvider> element, the only required element, defines the data storage provider to use as well as any necessary attributes required by the specific storage provider. Therefore, if the configuration storage provider used a database, you would probably have an attribute to specify a connection string to connect to the database. Table 2 contains a list of the configuration data providers included with the CMAB. Table 3 contains a listing of the configuration storage providers and the corresponding attributes.

The <protectionProvider> element specifies a data protection provider that can be used for signing and encrypting the stored configuration data. The CMAB comes with two DPPs. They are listed in Table 4. You can find the attributes for these two included DPPs in Table 5.

Table 3: Configuration Storage Provider attributes.

Configuration
Storage Provider (CSP)

Attributes



Description

(Common to all included storage providers)

Assembly

Specifies the assembly name that contains the storage provider. (Required.)

 

Type

Specifies the storage provider class inside the assembly to use. (Required.)

 

Signed

If set to true, the configuration data is signed and the data protection provider must be provided. (Optional.)

 

Encrypted

If set to true, the configuration data is encrypted and the Data Protection Provider (DPP) must be provided. (Optional.)

SqlStorage

connectionStringRegKeyPath

Specifies the Windows registry path where the SQL connection string is stored. (Either this setting or connectionString is required.)

 

connectionString

Specifies the SQL Connection string to use when connecting to a SQL database. (Either this setting or connectionStringRegKeyPath is required.)

 

getConfigSP

Specifies the stored procedure name used for returning configuration data. (Optional. Defaults to cmab_get_config.)

 

setConfigSP

Specifies the stored procedure name used for saving configuration data to the database. (Optional. Defaults to cmab_set_config.)

XmlFileStorage

Path

Specifies the path where the configuration data XML file is stored. (Optional. Defaults to search the application configuration file for a custom configuration element that matches the specified name attribute in the CSH custom configuration declaration.)

 

refreshOnChange

If set to true and when using the CMAB cache feature, any file modification made to the configuration data file refreshes the cached configuration data. (Optional.)

RegistryStorage

registryRoot

Specifies the registry root of where the configuration is stored. (Required.)

 

registrySubKey

Specifies the registry sub key where the configuration data is stored. (Required.)


Table 4: Out of the Box Data Protection Providers (DPPs).

DPP Class Implementations

Description

BCLDataProtection

Utilizes the .NET Cryptography libraries to handle encryption and decryption of configuration data. Utilizing this implementation means you will have to manage encryption keys manually.

DPAPIDataProtection

The DataProtection implementation utilizes the Win32 DPAPI or Data Protection API. This API handles the management of encryption keys for you. The encryption keys can be stored in the user key store, which, on a Windows NT domain with roaming profiles turned on, allows a user to encrypt and decrypt data on any computer on that domain. An alternative is to use the machine key store to allow anyone accessing that particular computer to encrypt and decrypt data.


Table 5: Configuration Storage Provider (CSP) attributes.

Data Protection
Provider

Attributes

Description

(Common to all included data protection providers)

Assembly

Specifies the assembly name that contains the storage provider. (Required.)

 

Type

Specifies the storage provider class inside the assembly to use. (Required.)

 

hashKeyRegistryPath

Specifies the Windows registry path where the hash key is stored. (Either this setting or hashKey is required.)

 

hashKey

Specifies the Hash key to use when encrypting data. (Either this setting or hashKeyRegistryPath is required.)

BCLDataProtection

symmetricKeyRegistryPath

Specifies the Windows registry path where the symmetric key is stored. (Either this setting or symmetricKey is required.)

 

symmetricKey

Specifies the symmetric key to use when encrypting data. (Either this setting or symmetricKeyRegistryPath is required.)

DPAPIDataProtection

keyStore

Specifies the key store to use. (Optional. Defaults to use the machine key to encrypt the data.)




Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date