redis serialize session in c # net asp mvc

0

I am using redis and I am trying to store the user session in an azure redis, I have tried storing strings in and it works with session.add("nombre", objeto) and it works for common and current string but when I try to save the session inside (since it is not because it does not do it automatically after configuring web.conf, when trying session.add("unasession",session); I get the error:

  

The type 'System.Web.HttpSessionStateWrapper' of the assembly   'System.Web, Version = 4.0.0.0, Culture = neutral,   PublicKeyToken = b03f5f7f11d50a3a 'is not marked as serializable.

    
asked by Zealot91 25.09.2018 в 16:22
source

1 answer

0

It does not work because the data you enter in the Session is not serialized. Serialize the data and that's it. The data can be serialized and de-serialized, when necessary. Take a look at: link

For example:

//Creamos objeto Coche
CocheCoche objCoche =new Coche
{ 
IdCoche = 1, 
Marca = "Mercedes", 
Modelo = "C220K" 
};

//Serializar objCoche a XMLstring 
xmlCoche = objCoche.SerializarToXml();

//Deserializar XML a objCocheCoche 
cocheDeserializado = xmlCoche.DeserializarTo<Coche>();

Luck:

    
answered by 25.09.2018 в 16:51