asp.net mvc why can not I create a Session [""] in a class? [closed]

-5

I find a big unknown and it is that it does not allow me to create a Session[""] in a class file only in a controller file.

Does anyone know what this is about or how could I create one there?

    
asked by vcasas 10.05.2018 в 20:47
source

1 answer

1

You should define the using a System.Web and use

HttpContext.Current.Session[]

the webpage inherits from Page, that's why you can directly access the Session object, but a class does not do it.

If that class executes within a web environment it could access the objects by means of HttpContext.Current

What is the difference between these two HttpContext.Current.Session and Session - asp.net 4.0

    
answered by 10.05.2018 / 22:00
source