Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure 1.4 MVC3会话状态和缓存_C#_Asp.net Mvc 3_Session_Azure_Session State - Fatal编程技术网

C# Azure 1.4 MVC3会话状态和缓存

C# Azure 1.4 MVC3会话状态和缓存,c#,asp.net-mvc-3,session,azure,session-state,C#,Asp.net Mvc 3,Session,Azure,Session State,在多个实例上运行时,我无法使用Azure缓存实现会话状态。 以下是我在学习各种教程时所做的: 1-设置缓存:我在旧azure管理门户中添加了缓存服务,在新门户中找不到缓存选项 2-更新web.config以包括以下内容: <configSections> <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection,

在多个实例上运行时,我无法使用Azure缓存实现会话状态。 以下是我在学习各种教程时所做的:

1-设置缓存:我在旧azure管理门户中添加了缓存服务,在新门户中找不到缓存选项

2-更新web.config以包括以下内容:

<configSections>
  <section name="dataCacheClients"
           type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core"
           allowLocation="true"
           allowDefinition="Everywhere" />
</configSections>

<dataCacheClients>
  <dataCacheClient name="default">
    <hosts>
      <host name="superSecretName.cache.windows.net" cachePort="22233" />
    </hosts>
    <securityProperties mode="Message">
      <messageSecurity authorizationInfo="superSecretAuthToken"></messageSecurity>
    </securityProperties>
  </dataCacheClient>
</dataCacheClients>

<system.web>
  <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
    <providers>
      <add name="AppFabricCacheSessionStoreProvider"
           type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
           cacheName="default"
           useBlobMode="true" 
           dataCacheClientName="default" />
    </providers>
  </sessionState>
</system.web>

跳一支快乐的舞蹈,直到一切崩溃和燃烧

从我在教程和示例中阅读的内容来看,这应该足够像往常一样在代码中使用
会话
,并让它在后台使用缓存。然而,似乎出现了随机的站点崩溃,我已经指出这是由于会话没有被填充。我在尝试访问已放入会话的数据时遇到空引用异常。我能想到的唯一解释是,azure实例被切换,缓存并没有真正分布在实例之间(尽管我可能错了)

我也尝试过不使用会话,而是使用自定义cookie,然后将内容保存在缓存中,并使用cookie值从缓存中检索数据,但同样的事情也发生了,所以我猜,破坏的不是会话,而是底层缓存


如标题所述,Azure版本为1.4。我使用的例子很可能是新版本的。切换到较新版本的Azure不是一个选项,因为许多其他库可能会中断。

请注意,缓存服务不是持久性的。它本质上是一个RAM存储器。它可能会被冲走。这种情况很少发生,但仍然可以发生。一种可能的解决方法是改用Azure SQL。