AppFabric缓存 - 远程主机强制关闭了一个现有的连接

7

我正在尝试在本地开发环境中启用AppFabric缓存。我已经安装了Windows Server AppFabric Beta 2 Refresh,并在Windows 7 64位上配置和启动了缓存集群和主机。我在本地IIS网站下的v4.0应用程序池中以集成模式运行我的MVC2网站。

HostName : CachePort      Service Name            Service Status Version Info
--------------------      ------------            -------------- ------------
SN-3TQHQL1:22233          AppFabricCachingService UP             1 [1,1][1,1]

我已经按照以下方式配置了我的web.config:

  <configSections>
        <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere"/>
   </configSections>

   <dataCacheClient>
       <hosts>
           <host name="SN-3TQHQL1" cachePort="22233" />
       </hosts>
   </dataCacheClient>

当我尝试初始化DataCacheFactory时,出现了错误:
    protected CacheService()
    {
        _cacheFactory = new DataCacheFactory(); <-- Error here
        _defaultCache = _cacheFactory.GetDefaultCache();
    }

我看到了ASP.NET黄色错误屏幕,并显示以下内容:

现有连接被远程主机强制关闭

描述: 在当前Web请求执行期间发生未处理的异常。请查看堆栈跟踪以获取有关错误的更多信息以及代码中出现的位置。

异常详细信息: System.Net.Sockets.SocketException: 现有连接被远程主机强制关闭

源错误:

Line 21:         protected CacheService()
Line 22:         {
Line 23:             _cacheFactory = new DataCacheFactory();
Line 24:             _defaultCache = _cacheFactory.GetDefaultCache();
Line 25:         }

真正的问题是,如果您的帐户没有访问权限,为什么服务器没有告诉您,而是显示“远程主机强制关闭了现有连接”? - felickz
3个回答

15

我也遇到了类似的问题,我的问题是没有给缓存客户端正确的权限。为了快速验证这是否是问题,我会授予所有用户访问缓存的权限。如果这解决了问题,那么请考虑限制适当账户的访问,而不是所有人。可以通过在“Caching Administrator Windows PowerShell”中执行以下命令来完成此操作,该工具可以在Windows Server AppFabric开始菜单文件夹中找到:

Grant-CacheAllowedClientAccount everyone

谢谢!我已经试图弄清楚这个问题一段时间了,你真是我的救星。 - Wallace Breza
2
这是一种懒惰的方法。更准确的解决方案是:Grant-CacheAllowedClientAccount "IIS AppPool\AppPoolOfYourApplicationAccessingTheCache" - John Zabroski

3

我也遇到了这个问题,并在以下帖子中找到了答案:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/c27063e7-1579-4d62-9104-87076d1c8d98/client-caching-error-errorcodeerrca0017substatuses0006

答案如下:

您看到此错误是因为客户端和服务器之间的安全属性不匹配。

在您的客户端代码中,您禁用了安全性(Mode=None和ProtectionLevel=None),而缓存服务器使用mode=Transport和PotectionLevel=EncryptAndSign(在Beta2Fresh位中默认)。

请执行以下操作之一:

1)在客户端代码中使用默认安全性,即configuration.SecurityProperties =new DataCacheSecurity();

2)在服务器上禁用安全性以与现有客户端代码匹配。 使用PowerShell cmdlet Set-CacheClusterSecurity -SecurityMode None -ProtectionLevel None


1
Set-CacheClusterSecurity -SecurityMode None -ProtectionLevel None 对我很有帮助。谢谢! - Alex

1

如果您使用 DataCacheFactoryConfiguration 对象,是否会遇到相同的问题?例如:

protected CacheService()
{
    DataCacheFactoryConfiguration config;
    List<DataCacheServerEndpoint> endpoints;
    DataCacheFactory factory;
    DataCache cache;

    endpoints = new List<DataCacheServerEndpoint>();
    endpoints.Add(new DataCacheServerEndpoint("SN-3TQHQL1",22233));

    config = new DataCacheFactoryConfiguration();
    config.Servers = endpoints;

    factory = new DataCacheFactory(config);

    cache = factory.GetDefaultCache();
    ...
}

你是否在防火墙上打开了端口?
也许可以检查事件日志中的条目,它们可能会提供关于正在发生或未发生的事情的线索。

是的,我也尝试过了。我已经逐步检查了所有配置,尽可能地进行了配置,一切似乎都配置正确。+1 - Wallace Breza
@Wallace 不确定,也许尝试重新安装? - PhilPursglove
重新安装也没有起作用。我目前正在联系微软,尝试解决这个问题。一旦我收到他们的回复,我会发布一个响应。 - Wallace Breza

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接