我正在使用会话包装器,如回答这里所述:How to access session variables from any class in ASP.NET?
但我不知道如何使用这个原则来做Session.Clear()和Session.Abandon()。
我的代码:
public class AppSession
{
// private constructor
private AppSession()
{
CurUser = new UserHolder();
}
// Gets the current session.
public static AppSession Current
{
get
{
AppSession session =
(AppSession) HttpContext.Current.Session["__AppSession__"];
if (session == null)
{
session = new AppSession();
HttpContext.Current.Session["__AppSession__"] = session;
}
return session;
}
}
// **** add your session properties here, e.g like this:
// Current app user
public UserHolder CurUser { get; set; }
}
答案 0 :(得分:0)
你可以很容易地做到:
public class AppSession
{
public void Clear()
{
//Remove items from the AppSession class
//Update AppSession instance in HTTP Context session
HttpContext.Current.Session["__AppSession__"] = this;
}