Storing session state data in an Azure environment

wirot thongchoojai asked on March 28, 2025 13:10

I will save the session to Redis on the live site, but the example (https://docs.kentico.com/13/deploying-websites/running-xperience-on-microsoft-azure/storing-session-state-data-in-an-azure-environment) suggests modifying the web.config file, which does not exist in the live site solution. What should I do?

Recent Answers


Brenden Kehren answered on March 28, 2025 14:27

Your CMS solution will have session state and the code should be added to the web.config file. Your .net core site typically does not have a web.config file, however, during the CI/CD process there is one created. What you can do to override that one is to include a web.config in your .net core project at the root of the project. It should have at least these the <xml> and opening and closing <configuration> nodes in it. Then your Redis Cache connection string goes in the <system.web> node. When the publish process publishes the website, it will merge the "custom code" you have with what is needed to run the site "auto-magically".

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!- your custom nodes go here -->
  <system.web>
    <sessionState mode="Custom" customProvider="MySessionStateStore">
      ...
    </sessionState
  </system.web>
</configuration>
0 votesVote for this answer Mark as a Correct answer

wirot thongchoojai answered on March 29, 2025 04:58

I am using Kentico version 13 refresh 13 and have installed the package named Microsoft.Web.RedisSessionStateProvider. I have also created a web.config file in .NET Core under the root of the DancingGoatCore project with the following configuration. Then, I ran dotnet run --no-build to start the project again, but when I checked in Azure Redis, no data had been stored.package install<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <sessionState mode="Custom" customProvider="MySessionStateStore"> <providers> <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="twirote.redis.cache.windows.net" accessKey="my_access_key" ssl="true" port="6380" /> </providers> </sessionState> </system.web> </configuration>

0 votesVote for this answer Mark as a Correct answer

wirot thongchoojai answered on March 29, 2025 05:06

I checked the event log and found no errors. How can I troubleshoot and fix this issue to ensure that the session is stored in Redis?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 29, 2025 05:13 (last edited on March 29, 2025 05:13)

Make sure you have your host populated too. The key and port alone won't make a connection. Also check the debug folder to ensure the web config has the values you added in it. If it doesn't, I'd suggest doing a build vs skipping that.

0 votesVote for this answer Mark as a Correct answer

wirot thongchoojai answered on March 29, 2025 05:28

The host (twirote.redis.cache.windows.net) of Azure that I configured in web.config is actually accessible from my computer. However, when I run dotnet run, I receive this warning message.

Do you think this could be the cause, and how should I resolve the issue?

C:\inetpub\wwwroot\Kentico13_2\DancingGoatCore>dotnet run Using launch settings from C:\inetpub\wwwroot\Kentico13_2\DancingGoatCore\Properties\launchSettings.json... C:\inetpub\wwwroot\Kentico13_2\DancingGoatCore\DancingGoatCore.csproj : warning NU1701: Package 'Microsoft.AspNet.SessionState.SessionStateModule 2.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net8.0'. This package may not be fully compatible with your project. C:\inetpub\wwwroot\Kentico13_2\DancingGoatCore\DancingGoatCore.csproj : warning NU1701: Package 'Microsoft.Web.RedisSessionStateProvider 5.0.4' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net8.0'. This package may not be fully compatible with your project. C:\inetpub\wwwroot\Kentico13_2\DancingGoatCore\DancingGoatCore.csproj : warning NU1701: Package 'Microsoft.AspNet.SessionState.SessionStateModule 2.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net8.0'. This package may not be fully compatible with your project. C:\inetpub\wwwroot\Kentico13_2\DancingGoatCore\DancingGoatCore.csproj : warning NU1701: Package 'Microsoft.Web.RedisSessionStateProvider 5.0.4' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net8.0'. This package may not be fully compatible with your project.

0 votesVote for this answer Mark as a Correct answer

wirot thongchoojai answered on March 29, 2025 05:34

I checked the debug folder and found the web.config file, and the values inside match what I had added. C:\inetpub\wwwroot\Kentico13_2\DancingGoatCore\bin\Debug\net8.0\web.config

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.