Programming Microsoft ASP.NET 4 - Dino Esposito [63]
aspnet_regiis.exe -pc YourContainerName -exp
Next, you export the key container to an XML file:
aspnet_regiis.exe -px YourContainerName YourXmlFile.xml
Next, you move the XML file to each server and import it as follows:
aspnet_regiis.exe -pi YourContainerName YourXmlFile.xml
As a final step, grant the ASP.NET account permission to access the container.
Note
For more information about the aspnet:_regiis tool and its command line, refer to the following URL: http://msdn.microsoft.com/en-us/library/k6h9cz8h(VS.80).aspx.
Creating Custom Configuration Sections
The predefined XML schema for configuration files fits the bill in most cases, but when you have complex and structured information to persist, none of the existing schemas appear to be powerful enough. At this point, you have two possible workarounds. You can simply avoid using a standard configuration file and instead use a plain XML file written according to the schema you feel is appropriate for the data. Alternatively, you can embed your XML configuration data in the standard application configuration file but provide a tailor-made configuration section handler to read it.
Creating a new section (plus an optional new section group) requires editing the web.config file to register the section (or section group). While registering the new section, you need to specify the section handler component—that is, the piece of software in charge of parsing the contents of the section to processable data. Depending on what kind of data you’re going to store in the section, you can use one of the existing handlers or, more likely, create your own section handler.
In ASP.NET, the configuration section handler is a class that ultimately inherits from the ConfigurationSection class. The section handler class defines public properties and maps them to attributes in the XML element. In addition, these class properties are decorated with a special attribute named ConfigurationProperty. The following example shows how to create the handler for a new public class MyPagesSection : ConfigurationSection { private static readonly ConfigurationProperty propPageBackColor = null; static MyPagesSection() { MyPagesSection.propPageBackColor = new ConfigurationProperty( "PageBackColor", typeof(string), "yellow", ConfigurationPropertyOptions.IsRequired); } [ConfigurationProperty("pageBackColor")] public string PageBackColor { get { return (string) base[MyPagesSection.propPageBackColor]; } set { base[MyPagesSection.propPageBackColor] = value; } } } The mapping between a property and a section attribute is established through the ConfigurationProperty attribute. The parameter of the attribute constructor indicates the name of the section attribute used to feed the decorated property. A custom section must be registered to work properly. Here’s how to do it: ... The type property in the