c# - Multiple Applications, Shared Settings: Use the registry or XML-based configuration? -
my landscape
I have an orbit library that is being called by several separately Executable Applications To gain access to this class library, it is necessary to know the address of the database server (and many other configuration options, information, etc.).
My question set H2>
Is it common to store these specific configuration options in the Windows registry? Thing, or Class library likes to use the specific 'App.config' XML approach to the configuration tool to change it and modify it?
I am leaning towards the Registry approach, but I know that many people have opinions about not using it. What would you do?
The best practice is to use the XML configuration file in the user's% appdata% directory.
There are several reasons for this:
- Your application is likely to be installed in the program file. If the user has not given the administrative authority (or given) the process of your application, then you will not be able to write the file.
- I have worked partially in a trusted environment where the registry access is not just an option. The client completely disabled the registry permissions for the .NET runtime on that server.
-
Your user should always have access to their own% appdata% directory. Here's a sample:
string configFilePath = environment. Gatefolder Path (Environmental Specialfolder. Application Data) + "myAppConfig.config"; ExeConfigurationFileMap Map = New ExeConfigurationFileMap (); Map.ExeConfigFilename = configFilePath; Configuration cfg = ConfigurationManager.OpenMappedExeConfiguration (map, configuration user .nn); Cfg.AppSettings.Settings.Add ("mySetting", "myValue!"); Cfg.Save (ConfigurationSaveMode.Modified); // MySetting = cfg.AppSettings.Settings ["mySetting"] to read the settings again. Values; // At this point, mySetting = "myValue!"
Remember to add the system. Configuration v2.0.0.0 References for your project! Default system The configuration namespace does not have all the required classes.
Comments
Post a Comment