我想基於http://msdn.microsoft.com/en-us/library/windowsazure/gg618003的代碼基於概念驗證。如果我使用app.config設置,此緩存是可訪問的。當我將應用程序切換到使用編程配置時,我始終得到這個錯誤。我已經嘗試Azure cache programatically configuration fail to verify和許多其他解決方案無濟於事。Azure緩存programatic配置導致ErrorCode ERRCA0029子狀態ES0001用戶傳遞的授權令牌無效
這是我的代碼片段。
{}代碼
String acsKey = "AcsKey removed intentionaly";
DataCacheFactoryConfiguration cacheFactoryConfiguration;
DataCacheSecurity dataCacheSecurity;
DataCacheServerEndpoint[] serverEndpoints = new DataCacheServerEndpoint[1];
SecureString secureAcsKey = new SecureString();
serverEndpoints[0] = new DataCacheServerEndpoint("EndPont removed intentionaly", 22243);
//
// Create SecureString from string
//
foreach (char keyChar in acsKey)
{
secureAcsKey.AppendChar(keyChar);
}
secureAcsKey.MakeReadOnly();
dataCacheSecurity = new DataCacheSecurity(secureAcsKey);
//
// Initialize Factory Configuration
//
cacheFactoryConfiguration = new DataCacheFactoryConfiguration(); // This line throws exception. Note that the key is yet to be assigned to SecurityProperties as per documentation.
cacheFactoryConfiguration.Servers = serverEndpoints;
cacheFactoryConfiguration.SecurityProperties = dataCacheSecurity;
_cacheFactory = new DataCacheFactory(cacheFactoryConfiguration);
_cache = _cacheFactory.GetDefaultCache();
{}代碼
我剛纔知道了這一點。我曾使用NuGet的安裝說明(導致文檔如此說明)。這增加了一個我沒有意識到的配置條目。它有文件的模板化版本並導致問題。一旦我刪除它,代碼開始正常工作。 – Chetan