# Using ConfigurationManager to load config from an arbitrary location

I'm creating an information accessibility part that will certainly be made use of in an internet site which contains a mix of timeless ASP and also ASP.NET web pages, and also require an excellent way to handle its configuration setups.

I would certainly such as to make use of a personalized ConfigurationSection, and also for the ASP.NET web pages this functions wonderful. Yet when the part is called using COM interop from a timeless ASP web page, the part isn't running in the context of an ASP.NET demand and also consequently has no expertise of web.config.

Exists a means to inform the ConfigurationManager to simply load the configuration from an approximate course (as an example ..\web.config if my setting up remains in the /bin folder)? If there is after that I'm assuming my part can drop back to that if the default ConfigurationManager.GetSection returns null for my personalized area.

Any kind of various other strategies to this would certainly rate!

129
2019-05-12 22:44:36
Source Share
Answers: 2

In enhancement to Ishmaeel is solution, the method OpenMappedMachineConfiguration() will certainly constantly return a Configuration object. So to examine to see if it filled you need to examine the HasFile building where real suggests it originated from a documents.

10
2019-05-18 06:41:31
Source

Try this:

System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap(strConfigPath); //Path to your config file
System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

131
2019-05-17 02:24:36
Source