Altaf Khatri
Altaf Khatri



RSS feed for http://www.AltafKhatri.com website. Twitter account of http://www.AltafKhatri.com website.
∗Recently Added - How to take care of Betta fighter fish and increase life span?  10/30/2013


Find me on web

 LinkedIn

 Facebook

 Twitter

Why machine.config values are not getting picked up?


While working on enterprise applications and otherwise situation arises when you want to share your configurations in machine.config for few of the following reasons:
  1. Want to share the same configuraiton across multiple websites/applications hosted on the same server.
  2. To secure configuration values from users who have access to app.config or web.config and not the machine.config


When machine.config is used, sometimes people face problems accessing the machine.config values. This causes delay in the release process. Debugging this mystery is time consuming and sometimes even causes release to be rolled back when the code is already deployed and config is the last thing to be applied.

I have faced the problem when accessing the machine.config values and thought of sharing my experiences . If it so happens then try to debug using the methods mentioned below:
  1. Clear tag in web.config/app.config - If you are accessing the keys from the configuration file then remember that the sequence for dotnet to access configuration is in the following heirarchy:
    1. Machine.config - First checked here
    2. Web.config in the machine.config folder - Consolidated with the entries here(I + ii)
    3. Web.config of the website - Consolidated with the entries here (I + ii + iii)
    4. Web.config of the folder in which the file exists - Consolidated with the entries here (I + ii + iii + iv)
    If the same key is found in multiple config files then ASP.net will complain that multiple values exists. To avoid this problem, most of the time there is clear tag in the relevant Settings section of the web.config of the website(Item iii above) to override the values in previous files.
    The syntax looks like this:

      <membership defaultProvider="ASPNETSqlMembershipProvider">

        <providers>

          <clear/>

          <add name="ASPNETSqlMembershipProvider" 

                  type="Authentication.Providers.ASPNETSqlMembershipProvider, AB.Authentication"

                  connectionStringName="ABCMembershipDB"              applicationName="ABWeb" />

        </providers>

      </membership>

    The clear tag above will remove the previous entries added in the providers section.

    Therefore, if your machine.config values are not getting picked up in your application then check the configuration files in the sequence mentioned above to see if clear tag is present. This could be the cause of the issue.

  2. 32 bit vs 64 bit machines and .net framework 4 - This applies to windows 64 bit version of operating system. When the machine is 64 bit then dotnet framework creates the following folder during installation:
    • c:\Windows\Microsoft.NET\Framework64 - for 64 bit version
    • c:\Windows\Microsoft.NET\Framework - for 32 bit version

    If during development you have 32 bit version and production has 64 bit version windows operating system installed then you will be surprised that your machine.config values are not getting picked. In machines running 64 bit operating system, updating the machine.config of 32 bit version, will not reflect the changes. So be careful to update appropriate machine.config based on your operating system.

  3. Load balancer IP same as the production server - This is a rarest of rare situation but it really happened. Sometimes infrastructure team assign the same IP to the load balancer and production server. So when you decide that before rolling out your changes to all the production boxes, you want to add the configuration changes to one box and test before rolling out the machine.config changes to all the servers, then you can be surprised.

    Machine.config values not getting picked up. Solution/resolution Now when you try to access Box1(where you have deployed the machine.config changes)from within the network with the help of IP address(in the above case - IP:192.1.1.1), then you can be in for a surprise. The load balancer will kick in because the IP of the load balancer is being called and it will send the request to any of the boxes. It will be very difficult to understand the random behavior of the request as to when load balancer sends the request to Box1 then everything works but if the request is directed to box 2 then the machine.config value is not picked. Be very careful, understand the infrastructure when you run into situation when machine.config values are not getting picked up.


Hope this helps.

Let me know if you run into any other issues with machine.config and have found solutions no matter how simple(stupid) they may be. Also, please feel free to post me questions if you are stuck with machine.config values not getting picked up.





SiteMap  |  Contact Me