using System;
using System.Configuration;
using System.Linq;
using System.Text;
namespace TestConfigurationManager
{
class Program
{
static void Main(string[] args)
{
// Get the AppSetting entries
for (int i=0; i < ConfigurationManager.AppSettings.Count; i++)
{
Console.WriteLine("AppSetting key: " + ConfigurationManager.AppSettings.AllKeys[i] + ", value: " + ConfigurationManager.AppSettings[i]);
}
// Get the Machine Config located at windows_root\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration();
ProtectedConfigurationSection protectedConfigSection = (ProtectedConfigurationSection) machineConfig.GetSection("configProtectedData");
Console.WriteLine("Protected provider default: " + protectedConfigSection.DefaultProvider);
Console.WriteLine("Here are the providers: ");
foreach (ProviderSettings settingsColl in protectedConfigSection.Providers)
{
Console.WriteLine("\t{0}", settingsColl.Name);
}
Console.ReadKey();
}
}
}
/*
Output:
AppSetting key: username, value: ptenn
AppSetting key: password, value: pass
AppSetting key: domain, value: mydomain
Protected provider default: RsaProtectedConfigurationProvider
Here are the providers:
RsaProtectedConfigurationProvider
DataProtectionConfigurationProvider
*/
Tuesday, October 27, 2009
Configuration Management
I wrote the following test class to practice using classes in System.Configuration, especially ConfigurationManager.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment