Konfiguration af Windows Azure Session og Output Caching

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg vil gerne bruge azurblå caching til at gemme session og output caching data. Min webkonfig er konfigureret som følger:


    <?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <configSections>
    <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere" />
  </configSections>

  <!-- Cache exposes two endpoints: one simple and other SSL endpoint. Choose the appropriate endpoint depending on your security needs. -->
  <dataCacheClients>
    <dataCacheClient name="default">
      <hosts>
        <host name="******" cachePort="22233" />
      </hosts>

      <securityProperties mode="Message">
        <messageSecurity
          authorizationInfo="******">
        </messageSecurity>
      </securityProperties>
    </dataCacheClient>

    <dataCacheClient name="SslEndpoint">
      <hosts>
        <host name="******" cachePort="22243" />
      </hosts>

      <securityProperties mode="Message" sslEnabled="true">
        <messageSecurity
          authorizationInfo="******">
        </messageSecurity>
      </securityProperties>
    </dataCacheClient>

  </dataCacheClients>

  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <httpRuntime executionTimeout="1000" maxRequestLength="1024000" enableVersionHeader="false" />
    <customErrors mode="Off" defaultRedirect="~/Home/PageNotFound" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>

    <!-- If session state needs to be saved in the Caching service, add the following to web.config inside system.web. If SSL is required, then change dataCacheClientName to "SslEndpoint". -->
    <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>

    <!-- If output cache content needs to be saved in the Caching service, add the following to web.config inside system.web. -->
    <caching>
      <outputCache defaultProvider="DistributedCache">
        <providers>
          <add name="DistributedCache"
               type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache"
               cacheName="default"
               dataCacheClientName="default" />
        </providers>
      </outputCache>
    </caching>

  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.SQLEXPRESS;Initial Catalog=******;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>


Men jeg får denne fejlmeddelelse, efter jeg har indsat i sessionen og output caching bits:


Skriv 'Microsoft.ApplicationServer.Caching.HostNodeDomainConfigurationElementCollection'. En ugyldig samlingstype, da den ikke har en gyldig Tilføj metode med parameter af typen 'System.Object'.


De bits jeg indsatte ind for at aktivere session og output caching:


<!-- If session state needs to be saved in the Caching service, add the following to web.config inside system.web. If SSL is required, then change dataCacheClientName to "SslEndpoint". -->
<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>

<!-- If output cache content needs to be saved in the Caching service, add the following to web.config inside system.web. -->
<caching>
  <outputCache defaultProvider="DistributedCache">
    <providers>
      <add name="DistributedCache"
           type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache"
           cacheName="default"
           dataCacheClientName="default" />
    </providers>
  </outputCache>
</caching>


Når jeg fjerner disse bits og lader det som før med sessionState mode='InProc' ... alt fungerer fint. Kan nogen se, hvad jeg gør galt?


Hilsen,
Røve

Bedste reference


For at konfigurere Azure AppFabric Cache for sessionstilstand skal du have logget ind på Azure Portal og oprettet en cache.


Klik derefter på linket for at få config-uddraget og indsæt det i din config-fil, og offentliggør derefter din app.


Her er et link til HowTo gå gennem Azure-webstedet: http://www.windowsazure.com/en-us/develop/net/how-to-guides/cache[3]


Jeg har implementeret det på denne måde til session med succes.

Andre referencer 1


Jeg fandt problemet, det var fordi jeg brugte de forkerte caching DLL'er til Azure Caching i mit projekt.


Jeg henter dette:


http://www.microsoft.com/download/en/details.aspx?id=15848[4]


og derefter opgraderingen:


http://www.microsoft.com/download/en/details.aspx?displaylang=enu0026amp;id=19925[5]