2010-06-30 58 views
1

我有我的驗證配置存儲在我的業務對象項目中的validation.config中。配置文件設置爲複製,如果更新Enterprise Library 5:如何配置FileConfigurationSource相對於asp.net web應用程序文件夾?

業務對象項目被我的Web項目引用,因此,validation.config將複製到我的Web應用程序的bin文件夾中。

在我的web.config我有驗證配置重定向:

<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source"> 
<sources> 
    <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    <add name="ValidationConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
    filePath="bin\validation.config" /> 
</sources> 
<redirectSections> 
    <add sourceName="ValidationConfigurationSource" name="validation" /> 
</redirectSections> 

但是,使用procmon中我可以看到它正試圖從C加載配置:\ WINDOWS \ SYSTEM32 \ BIN \ validation.config

FileConfigurationSource的源似乎沒有任何關於使用AppDomain.CurrentDomain.BaseDirectory創建路徑的內容,所以我不確定相對路徑如何與asp.net一起工作

我怎樣才能得到這個工作的ASP.NET應用程序?

我在XP上使用本地IIS服務器以調試模式啓動時運行。

編輯

對不起,只是意識到有申請這兩個開放的問題:

http://entlib.codeplex.com/workitem/26990

http://entlib.codeplex.com/workitem/26760

如果我想出了一個解決辦法,我會張貼在這裏。

回答

1

要修復Microsoft企業庫源代碼中的代碼,請使用下面顯示的代碼替換FileConfigurationSource.cs中的以下方法。修改後的代碼會在創建根文件路徑後移動文件存在檢查。

private static string GetRootedCurrentConfigurationFile(string configurationFile) 
    { 
     if (string.IsNullOrEmpty(configurationFile)) 
      throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "configurationFile"); 


     string strPath = 
      Path.IsPathRooted(configurationFile) 
      ? configurationFile 
      : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configurationFile); 

     if (!File.Exists(strPath)) 
     { 
      throw new FileNotFoundException(
       string.Format(
        CultureInfo.CurrentCulture, 
        Resources.ExceptionConfigurationLoadFileNotFound, 
        configurationFile)); 
     } 
     return strPath; 
    } 
+1

我相信此問題已在位於此處的Entlib 5可選更新1中得到糾正:http://www.microsoft.com/download/en/details.aspx?id=6836 – 2011-09-28 17:23:43

相關問題