8

I am trying to implement Azure cache for redis to manage session's in my application. This is working on localhost. After hosting to IIS got compile error in webconfig file.

I have created azure cache for redis in azure portal. I have made respective changes in code. It's working when I run with source code on local host. After hosting to IIS got the following error

"Provider must implement the class
System.Web.SessionState.SessionStateStoreProviderBase

<sessionState mode="Custom" customProvider="MySessionStateStore">
      <providers>
        <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="myhostname" accessKey="Key1" ssl="true" />
      </providers>    
    </sessionState>

Module added as following

<system.webServer>
    <modules>
      <remove name="Session" />
      <add name="Session" type="Microsoft.AspNet.SessionState.SessionStateModuleAsync, Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode" />
    </modules>
  </system.webServer>

I expected sessions values to store on azure cache for redis. But It's not working after hosting on IIS.

user3404686
  • 131
  • 2
  • 10
  • are you transforming your web.config when deploying to IIS? – DdW Oct 18 '19 at 08:36
  • @DdW - I'm having the same issue - have the config as above and am transforming the web.config via octopus deploy when deploying to an Azure App Service – CodeFirstAndy Mar 19 '20 at 15:44
  • @anD666 Be careful with transforming, especially the modules section is tricky. Look at the transformed endresult, and compare with the local version. – DdW Mar 19 '20 at 21:41
  • @DdW - The transformation isn't touching the modules section. it's just adding the session state section. – CodeFirstAndy Mar 20 '20 at 08:49
  • @anD666 you need the modules section as well... – DdW Mar 20 '20 at 12:04
  • @DdW - sorry, poor explanation in my previous comment. The module for the SessionStateModuleAsync is already in the web.config. When I pull down the files from the web server they are as expected. The extracted web directory even works locally so I'm at a loss – CodeFirstAndy Mar 20 '20 at 12:26
  • Any news on this? I'm facing the same issue – Steeven Diard Jul 30 '20 at 11:42

2 Answers2

7

You can try this under app.config/web.config

<modules>
<remove name="Session" />
<add name="Session" type="Microsoft.AspNet.SessionState.SessionStateModuleAsync,Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode" />

if this doesn't work as well, if you have an option, use non-SSL port and see if that works.

Amit
  • 191
  • 4
  • 14
0

For anyone passing by that might have the same issue and for whom adding the Session tag didn't work, your application pool might be configured as 'Classic'

From this post, it seems Microsoft.AspNet.SessionState.SessionStateModuleAsync doesn't support classic application pools

You need to switch it to 'Integrated' like so :

enter image description here

Microsoft official application pools documentation