2012-04-12 37 views
1

我有一個(網站| Windows)應用程序和一個DLL(類庫)。我想要在dll中獲取根(網站|窗口)配置文件路徑。獲取根配置文件路徑在DLL內

我試着ConfigurationManager.OpenExeConfiguration與不同的assembly.get的,但他們總是給的DLL配置路徑。

感謝

回答

0

嗨發現這一點,它工作得很好

Configuration config; 

     if (System.Web.HttpContext.Current != null && 
      System.Web.HttpContext.Current.Request.PhysicalPath.Equals(String.Empty) == false) 
     { 
      config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath); 
     } 
     else 
     { 
      config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
     } 

Basicly它會得到的web.config如果它是一個網站,它會得到app.exe.config如果一個Windows應用程序