Which is the best way to use it.
The second one seems the best. Although I would probably write those two as extension methods to the HttpSessionStateBase instead of putting them into a base controller. Like this:
public static class SessionExtensions
{
public static T GetDataFromSession(this HttpSessionStateBase session, string key)
{
return (T)session[key];
}
public static void SetDataInSession(this HttpSessionStateBase session, string key, object value)
{
session[key] = value;
}
}
and then inside the controllers, or helpers, or something that has an instance of HttpSessionStateBase
use it:
public ActionResult Index()
{
Session.SetDataInSession("key1", "value1");
string value = Session.GetDataFromSession("key1");
...
}
Writing session wrappers is useless in ASP.NET MVC as the HttpSessionStateBase
provided by the framework is already an abstract class which could be easily mocked in unit tests.