Sessions in ASP .NET Core 1.0 and ASP .NET MVC 4

3

I am doing a series of tests in ASP.NET MVC Core 1.0 to see if it is convenient to migrate the project from MVC 4 to MVC Core 1.0 many of the errors that came out are already fixed.

I have problems passing the parameters that contain sesionManange :

sesionManage.cuenta = WAutofactura_Respuesta.email;
sesionManage.devKey = WAutofactura_Respuesta.DevKey;
sesionManage.schema = WAutofactura_Respuesta.Schema;
sesionManage.mobileKey = WAutofactura_Respuesta.MobileKey;

which the problem is this line:

HttpContext.Session["sessionManage"] = sesionManage;

So my question is How can I pass the parameters of the variable sesionManange to a variable HttpContext.Session in ASP.NET MVC Core 1.0?

EDIT 1
Investigating a bit more in the session variables I found this method to serialize my model of sesionManange :

public static class SessionExtensions
{
    public static T GetObject<T>(this ISession session, string key)
        where T : class
    {
        var json = session.GetString(key);
        if (json == null)
        {
            return null;
        }
        return JsonConvert.DeserializeObject<T>(json);
    }
    public static void SetObject(this ISession session, string key, object value)
    {
        var json = JsonConvert.SerializeObject(value);
        session.SetString(key, json);
    }
}

Which marks me errors in GetObject<T> and SetObject , this is the error that marks me:

  

Extension methods must be defined in a top level static class; SessionExtensions is a nested class

    
asked by JuankGlezz 30.06.2016 в 01:38
source

1 answer

0

The error it gives you has nothing to do with the sessions, but the class SessionExtensions is nested inside another and the static classes that define extension methods can not be nested within others.

Take it out and at least not give that error.

    
answered by 22.02.2017 в 22:24