Redis Session in ASP.Net Web Forms
1. Download Redis installation package
official website address:https://redis.io/
Available download Url: https://github.com/MicrosoftArchive/redis/releases
2. Install Redis by double clicking the package "Redis-x64-3.0.504.msi", then got the following files
3. Start Redis Service
First, double-click the executable file "redis-server.exe" to start the Redis service. At this point, Redis will run in the background. Then, double-click the executable file "redis-cli.exe" to interact with Redis. Here, "127.0.0.1" represents the local host IP, and "6379" is the default Redis port number.
4. Install Redis Insight from Microsoft Store
5. Install the package RedisSessionStateProvider in project
6. Configue the sessionState under <system.web>
<sessionState mode="Custom" customProvider="MySessionStateStore" timeout="10"> <providers> <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="127.0.0.1" accessKey="" ssl="false" throwOnError = "true" retryTimeoutInMilliseconds = "5000" connectionTimeoutInMilliseconds = "5000" operationTimeoutInMilliseconds = "1000" databaseId = "0" /> </providers> </sessionState>
7. Add the follwing settings under <configuration>
<system.webServer> <modules> <remove name="Session" /> <add name="Session" type="Microsoft.AspNet.SessionState.SessionStateModuleAsync, Microsoft.AspNet.SessionState.SessionStateModule, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,managedHandler" /> </modules> </system.webServer>
8. Then you can use Redis Session just like common session
9. The session in Redis using Redis Insight
It's very simple to use redis session using this mode.