我们使用Windows Server AppFabric Cache 6.1 x64。如果区域名称包含“!”之类的字符,则拥有Microsoft.ApplicationServer.Caching.DataCache
实例并尝试按键/区域获取对象会导致DataCacheException
或'。':
ErrorCode<ERRCA0018>:SubStatus<ES0001>:The request timed out.
' - ','_'很好。但是,任何字符都适用于项目键,但不适用于区域名称。 MSDN对任何限制都保持沉默。为什么?你怎么逃避它?
答案 0 :(得分:1)
结束这一次:
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;
}