ASP.NET accessing session variables in class modules

By , May 14, 2009 4:30 pm

Sessions are a great way to share variable across your entire application, but they’re not accessable directly in class modules since they’re outside of page scope. So if you try something like Session(“VariableName”) = value ¬†inside of your class, you will get an error.

Fortunately there is a way.¬† Thru HttpContext.Current notation available such common properties as Session, Server, Application, Cache. So to access your session variable inside a class just use HttpContext.Current.Session(“VariableName”) = value

Leave a Reply

Panorama Theme by Themocracy