cvsayani
asked on
Handling session in common place in asp.net
Can we handle all session in a single static class like ?
public static class SessionManager
{
// Will it be a problem to assign a object like this?
public static Criteria SearchCriteria
{
get{
Criteria searchCriteria = HttpContext.Current.Sessio n["SearchC riteria"] as Criteria;
if(searchCriteria ==null)
{
searchCriteria =new Criteria();
}
return searchCriteria ;
}
set{
HttpContext.Current.Sessio n["SearchC riteria"] =value;
}
}
// Will it be a problem to assign a string like this?
public static string UserName
{
get{
string userName= HttpContext.Current.Sessio n["UserNam e"] as string;
if(string.IsNullOrEmpty(Is userName))
{
userName=<<CurrentUser>>;
}
return userName;
}
set{
HttpContext.Current.Sessio n["userNam e"] =value;
}
}
}
is this a good idea ?
public static class SessionManager
{
// Will it be a problem to assign a object like this?
public static Criteria SearchCriteria
{
get{
Criteria searchCriteria = HttpContext.Current.Sessio
if(searchCriteria ==null)
{
searchCriteria =new Criteria();
}
return searchCriteria ;
}
set{
HttpContext.Current.Sessio
}
}
// Will it be a problem to assign a string like this?
public static string UserName
{
get{
string userName= HttpContext.Current.Sessio
if(string.IsNullOrEmpty(Is
{
userName=<<CurrentUser>>;
}
return userName;
}
set{
HttpContext.Current.Sessio
}
}
}
is this a good idea ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
These methods are just wrappers around the Session variable. Since there is no state contained in the class, there are no thread issues.
ASKER
Thanks Sage.
ASKER