C# ASP.NET会话包装器会话。放弃()如何
我使用的会话包装器如下面的答案所述: 但是我不知道如何使用这个原则来执行Session.Clear()和Session.弃置() 我的代码:C# ASP.NET会话包装器会话。放弃()如何,c#,asp.net,session-state,asp.net-session,C#,Asp.net,Session State,Asp.net Session,我使用的会话包装器如下面的答案所述: 但是我不知道如何使用这个原则来执行Session.Clear()和Session.弃置() 我的代码: public class AppSession { // private constructor private AppSession() { CurUser = new UserHolder(); } // Gets the current session. public static A
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;
}
您想放弃实际会话还是仅放弃AppSession?因为您可以通过HttpContext.current.session访问当前会话,并且只需对其调用Clear()或放弃()。您能否解释一下调用“this”将如何清除实际对象?对mee来说,它似乎只是在包装器类中返回带有get方法的实例?