This snippet will allow you to easily work with session variables in your applications. This example is using a string type but it works the same for any data type, you would just need to change the default return value from string.Empty to something more appropriate.
Session backed properties
public string PropertyName
{
get
{
object temp = Session["PropertyName"];
// Returns an empty string if the session variable is null
// otherwise it casts the session variable to a string and returns it
return temp == null ? string.Empty : temp as string;
}
set
{
Session["PropertyName"] = value;
}
}
LastMitch
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.