0

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

1 回答 1

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;
   }
于 2015-12-01T15:08:59.580 回答