ASP.NET会话包装器Session.放弃()如何
本文关键字:放弃 如何 Session NET 会话 包装 ASP | 更新日期: 2023-09-27 18:25:21
我正在使用会话包装器,如这里的答案所述:如何从ASP.NET中的任何类访问会话变量?
但我不知道如何使用这个原理来执行Session.Clear()和Session.Advant()。
我的代码:
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; }
}
您可以轻松完成:
public class AppSession
{
public void Clear()
{
//Remove items from the AppSession class
//Update AppSession instance in HTTP Context session
HttpContext.Current.Session["__AppSession__"] = this;
}