c# - How to use HttpContext.Current.Session in static property of a abstract class.? -


i have controllerbase abstract class , below.

using system.web; using system.web.mvc; public abstract class controllerbase : controller {     public static string sesssionid     {          { return httpcontext.current.session["sessionid"]; }     } } 

i getting error

"object reference required non-static field, method, or property 'system.web.mvc.controller.httpcontext.get"

however have used same in other static classes , have not got above error.

i wonder how httpcontext being accessable not current.

could clarify me, wrong above.

your base class controller specifies httpcontext property itself. so, when using in derived class controllerbase, compiler thinks want refer property of base class.

you either make property non-static, wudzik suggested in first comment. guess cleaner way it.

if need keep property static, have tell compiler, want use httpcontext class of namespace system.web:

public static string sesssionid {      { return system.web.httpcontext.current.session["sessionid"]; } } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)