Section 3 – Configuration Files

What am I learning about configuration files?

Most important:  What do you PUT in configuration files?  Assembly locations.  Configuration strings.  Remote connection settings.  Stuff like that.

  •  What is an assembly?  An execution unit:  .dll or .exe 
  •  Config files are XML files
  • System.Configuration namespace can READ config files.  I read it cannot write, but it can…
  • Most of this is from the Visual Studio documentation.  Look up “Configuration”.

TODO:

  • So what’s a manifest? 

Sections in a configuration file:

  • Startup Settings – Specifies which version of the CLR to use.
  • Runtime Settings –  Specifies garbage collection and assembly versions
  • Remoting Settings –
  • Network Settings – how to connect to the Internet.   
  • Cryptograph Settings –
  • Configuration Sections – defines custom configuration sections.  Such as???
  • Trace and Debug settings
  • ASP.NET Configuration Settings – for ASP.Net apps only
  • Web Services Settings
  • Compiler and Language Provider Settings

Types of configuration files:

1.  Machine.Config
Contains global settings, such as shared assembly locations.  Located in the framework runtime path. 
For example, “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.config”.
One Machine.config per runtime per computer, I assume.
– machine-wide assembly bindings
– built-in remoting channels

2.  Application
– contain settings specific to an application.
– The CLR reads this for assembly binding policy, remoting objects, etc.
– The applications reads this too. 
– Where is the config file located?
— For an exe file, the config file is located in the same directory.  The name is [AppName].exe.config.
— For an ASP.Net file, ???
— For an Internet Explorer-hosted location … such as what? <link rel=”ConfigurationFileName” href=”location” mce_href=”location”>

3.  Security
– Use the .NET Framework Configuration tool (Mscorcfg.msc) to modify security policy
– There are three levels of security config files:
— Enterprise policy located in Framework runtime path “Enterprisesec.config”
— Machine policy located in Framework runtime path “Security.config”
— User policy located in “%USERPROFILE%\Application data\Microsoft\CLR security config\vxx.xx\Security.config”

(Publisher????)

Fuslogvw.exe

  • This is a cool little program that comes with the .NET SDK.  It lets you see a log of the assemblies as they get loaded.  If you get a loading error, you can see where it expected to find the assembly but didn’t.  To get it to work correctly, I had to go into settings and check the “Enable custom log path” option.  Otherwise, it seemed to only intermittently show binding information.

Procedure:

  • Run Fuslogvw.exe
  • Click the Settings button.  Check the “Enable custom log path” option.  Enter a custom log path.  Select some option other than “Log disabled”, depending on how much information you want to see. Use “Log all binds to disk” to see everything.
  • Run the application
  • Click the Refresh button in Fuslogvw.exe
  • You should see a list of bindings displayed.  Double click on a binding to see the log information.

 SO what does all this have to do with System.Configuration?

  • System.Configuration.ConfigurationManager in .NET 2.0 replaces System.Configuration.ConfigurationSettings in 1.1. 
  • Use WebConfigurationManager for ASP.NET configuration.
  • Things you can access:  connectionStrings,
  • Caller must have permission to read configuration settings.
  • IMPORTANT:  Project needs to have a reference to System.Configuration.dll 

This is so depressing – I have been studying for HOURS, and I haven’t even started to look at the classes that the exam guide says to know.  So far, it’s all just been preparation!!

From the 70-536 Exam Preparation Guide:   Embed configuration management functionality into a .NET Framework application. (Refer System.Configuration namespace)

Configuration class and ConfigurationManager class

Discoveries from trying the example in the Visual Studio documentation on the AppSettingsSection class:

  • If a configuration file does not exist, then calling config.AppSettings.Settings.Add will add the setting in memory, but it doesn’t actually write it to a file.
  • Call ConfigurationManager.RefreshSetting to reload the new setting into memory
  • If the AppName.exe.config file does exist, then running AppName.exe will update the file. 
  • The AppName.vshost.exe.config file is initially the same as the AppName.exe.config file.  If you run the application from Visual Studio, it will update the vshost config file temporarily AS LONG AS THE APP IS RUNNING!  Then it reverts back to the initial version.
  • What kind of permission does the app need to be able to write the file???

This article in MSDN magazine Parameterize Your Apps Using XML Configuration In The .NET Framework 2.0 looks interesting.

 To be continued…

Advertisements

Post a Comment

Required fields are marked *
*
*

%d bloggers like this: