How to find path of active app.config file?

后端 未结 8 2013
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 04:43

I\'m trying to finish this exception handler:

if (ConfigurationManager.ConnectionStrings[\"ConnectionString\"]==null)
{
    string pathOfActiveConfigFile = .         


        
相关标签:
8条回答
  • 2020-12-02 05:41

    Try this

    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
    
    0 讨论(0)
  • 2020-12-02 05:41

    I tried one of the previous answers in a web app (actually an Azure web role running locally) and it didn't quite work. However, this similar approach did work:

    var map = new ExeConfigurationFileMap { ExeConfigFilename = "MyComponent.dll.config" };
    var path = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None).FilePath;
    

    The config file turned out to be in C:\Program Files\IIS Express\MyComponent.dll.config. Interesting place for it.

    0 讨论(0)
提交回复
热议问题