There is nothing wrong with the idea, but there is a bug in the sample (see the fix below). Another problem is using
immediate constant and repeating it twice. How are your going to support it? All constants should be explicit, except some trivial ones like 0, 1, or null. But it could be fixed like this:
public static class TestClass
{
const string SessionId = "MyApplication_TestProperty";
public static string TestProperty {
get{
return HttpContext.Current.Session[SessionId].ToString();
}
set{
HttpContext.Current.Session[SessionId] = value;
}
}
}
It will work but is not flexible. More universal and general approach is using the
singleton pattern, see:
http://en.wikipedia.org/wiki/Singleton_pattern[
^],
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)[
^].
This is a good article with implementation samples in C#. I suggest you learn how to use the pattern:
http://csharpindepth.com/Articles/General/Singleton.aspx[
^].
Good luck.
—SA