asp.net - 在 Azure 云服务中启用共置 session 缓存

标签 asp.net asp.net-mvc session caching azure

现在,我有一个托管 MVC 应用程序的 Azure 云服务,当前,当使用 Staging <> Production 中的 VIP 交换方法进行更新时,会终止所有 session 。我还没有对 session 管理进行任何配置,所以这是可以预料的。

我现在尝试通过以下链接解决此问题:

http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-in-role-cache/

我已启用角色内缓存。我的 dataCacheCLients 如下所示:

<dataCacheClients>
    <dataCacheClient name="default">
      <!--To use the in-role flavor of Windows Azure Cache, set identifier to be the cache cluster role name -->
      <!--To use the Windows Azure Cache Service, set identifier to be the endpoint of the cache cluster -->
      <autoDiscover isEnabled="true" identifier="MyRoleName" />
    </dataCacheClient>
  </dataCacheClients>

上面的链接指向此处实际设置 session 缓存的 web.config:

http://www.windowsazure.com/en-us/manage/services/cache/net/how-to-in-role-cache/#store-session

我已在 web.config 中取消注释该部分(仅 session 缓存),现在如下所示:

 <!-- Windows Azure Cache session state provider -->
    <sessionState mode="Custom" customProvider="AFCacheSessionStateProvider">
      <providers>
        <add name="AFCacheSessionStateProvider" type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" applicationName="AFCacheSessionState"/>
      </providers>
    </sessionState>
    <!-- Windows Azure Cache output cache provider -->
    <!--Uncomment this section to use Windows Azure Cache for output cache-->
    <!--<caching>
      <outputCache defaultProvider="AFCacheOutputCacheProvider">
        <providers>
          <add name="AFCacheOutputCacheProvider" type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" applicationName="AFCacheOutputCache" />
        </providers>
      </outputCache>
    </caching>-->

现在,当我在本地运行此程序(未使用模拟器,仅使用 IIS 中的 MVC 应用程序)时,出现以下错误:

None of the discovered or specified addresses match the socket address family. Parameter name: context

我在这里没有了解太多细节,它只是被抛出到源不可用窗口中。

因此,我认为这可能只是一个本地问题,我可以稍后再担心,所以我将其发布到了 Azure。该应用程序运行良好。但部署和 VIP 交换会中断 session ,因此它似乎不起作用。

这可能是什么原因造成的?我尝试严格遵循所有指示。

我注意到的一件事是,链接到的最后一篇文章来自 Azure 缓存教程 - 我从未设置过 Azure 缓存,因为我将存储帐户与我的共置角色一起使用(根据上一个教程)。是什么原因导致这些问题?

最佳答案

是的,我认为您遇到的情况是正确的。

首先,您的本地测试失败是因为您启动了 MVC 应用程序。通过这种方式,您的应用程序在没有 azure 模拟器的情况下运行,这意味着缓存客户端无法从角色名称(您在 web.config 中指定的 identifier 部分)找到缓存端点。我认为如果您在本地模拟器上运行应用程序,它应该可以工作。

其次,当您交换 VIP 时,您的 session 应该会丢失。角色内缓存利用部分角色实例的内存。当您交换 VIP 时,公共(public) IP 将被配置到另一个插槽,这意味着您的缓存实例也将被切换。为了解决这个问题,我希望您尝试新的缓存服务(预览版)。通过这种方式,您可以为您的订阅创建专用缓存,以便您可以跨云服务部署、虚拟机和网站使用它们。

希望这有帮助。

关于asp.net - 在 Azure 云服务中启用共置 session 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20964697/

相关文章:

ios - 登录 iOS 应用程序和使用 Rails 设计后的 session 保留

c# - 如何从代码隐藏在新窗口或选项卡中打开页面

c# - ASP.NET MVC3 从部分 View 上传文件(并填写模型中的相应字段)

php - Guzzle cookies 处理

c# - 动态 JsonProperty

asp.net - ASP.NET MVC 5发布预编译问题

authentication - 授权服务器上的 session 起什么作用?

javascript - 如何检查更改事件的复选框状态

asp.net - asp.net页面生命周期

asp.net - 在 Azure 中配置 IIS 日志记录字段