AppFabric Cache中的区域名称限制

问题描述:

我们使用Windows Server AppFabric Cache 6.1 x64。具有Microsoft.ApplicationServer.Caching.DataCache的实例并试图通过键/区域获取对象会导致DataCacheException如果区域名称包含字符'!'或'。':AppFabric Cache中的区域名称限制

ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out. 

' - ','_'很好。但是,任何字符都适用于项目键,但不适用于区域名称。 MSDN对任何限制都保持沉默。为什么?你如何逃避它?

结束了这一个:

static Regex regex = new Regex(@"[^a-zA-Z_\-\d]", RegexOptions.Compiled); 

    /// <summary> 
    /// Fixes invalid characters in region names that cause 
    /// DataCacheException ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out. 
    /// </summary> 
    /// <param name="name">Region name to process.</param> 
    /// <returns>Escaped name where all invalid characters are replaced with their hex code.</returns> 
    protected internal static string Escape(string name) 
    { 
     if (string.IsNullOrEmpty(name)) 
      return name; 

     string result = regex.Replace(name, m => ((int)m.Value.First()).ToString("X")); 
     return result; 
    }