我正在使用会话包装器,如此处回答中所述:如何从 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; }
}