I already installed the library RedisSessionStateProvider
and its dependency StackExchange.Redis.StrongName
, also put the configuration in theweb.config
<sessionState mode="Custom" customProvider="RedisSessionProvider" cookieless="true" >
<providers>
<add name="RedisSessionProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider" port="6380" host="XXX.redis.cache.windows.net" accessKey="OQm………15E=" ssl="true" connectionTimeoutInMilliseconds="5000" operationTimeoutInMilliseconds="1000" retryTimeoutInMilliseconds="3000" writeExceptionsToEventLog="true" />
</providers>
</sessionState>
But it didn't get the session to be stored in redis , but if I make the connection in code the connection is successful, here is my code:
/// se crea la conexión
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
var redisOption = new ConfigurationOptions();
return ConnectionMultiplexer.Connect("XXX.redis.cache.windows.net:6380,abortConnect=false,ssl=true,password=OQmAPmp0 . . . . TJE15E=");
});
///regresa el objeto de la conexion
public static ConnectionMultiplexer Connection
{
get
{
return lazyConnection.Value;
}
}
///creo la session y agrego elementos manualmente al redis
public ActionResult SessionStart()
{
IDatabase cache = Connection.GetDatabase();
Session["loginTime"] = DateTime.Now.ToString();
string strValue = "myvalue";
Session.Add("myvalue ", strValue);
return View();
}
For example what I add manually is stored successfully but if I create a session it is not stored automatically, I think I need something else but not what it is.
I just did it from my own project with no problems, use this code to test it in your environment. I recommend that you try it in a clean project, you may have something wrong in your web.config that is not allowing the provider to load and you have not noticed it
web.config
and just with this in my home controller (or whatever you want)
HomeController/Index
To verify the values I use Redis Desktop Manager
I would recommend following guides like this
How to Use Azure Redis Cache
to implement redis integrated in your application that you publish in azure. After following that guide, if you continue with problems, it could be analyzed, but we start from a base that you have implemented.
Looking a little deeper I can see an implementation that configures the session state using redis
ASP.NET Session State Provider for Azure Redis Cache
The truth is that I had always seen redis used as cache objects or in conjunction with an orm such as entity framework, but I see that it can also replace asp.net objects
Cheers