Sitefinity - 注销后删除会话

时间:2015-07-14 18:46:11

标签: session global-asax sitefinity

我试图在用户退出Sitefinity页面后清除HttpContext.Current.Session。

我在这个link中看到你可以查看Request.Url,但我并不完全确定实现是什么。

这是我目前的尝试:

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    if (((System.Web.HttpApplication)(sender)).Request.Url.ToString() == HttpContext.Current.Server.MapPath("~/Sitefinity/Login/DoLogout"))
    {
        if (HttpContext.Current.Session["Cart"] != null) HttpContext.Current.Session.Remove("Cart");
        HttpContext.Current.Session["Cart"] = new List<IQuoteResult>();
    }
}

如果您有任何提示或建议,或者我的逻辑完全出错,请与我们联系。

提前致谢。

更新:

protected void Application_PostAcquireRequestState(object sender, EventArgs e)
    {
        if (((HttpApplication)(sender)).Request.Url.ToString().Contains("sign_out=true"))
        {
            if (HttpContext.Current.Session["Cart"] != null)
            {
                HttpContext.Current.Session.Remove("Cart");
                HttpContext.Current.Session["Cart"] = new List<IQuoteResult>();
            }
        }
    }

这是我完成相同任务的下一次尝试,但我一直收到NullReferenceException ...

注意:我还在Application_AcquireRequestState方法中尝试了这种方法。

这是堆栈:

[NullReferenceException: Object reference not set to an instance of an object.]
SitefinityWebApp.Global1.Application_PostAcquireRequestState(Object sender, EventArgs e) +137
 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +91
 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +164

1 个答案:

答案 0 :(得分:2)

这最终成为我的解决方案:

public bool IsUserLoggingOut { get; set; }

protected void Application_PostAcquireRequestState(object sender, EventArgs e)
{
    if (((HttpApplication)(sender)).Request.Url.ToString().Contains("/Sitefinity/SignOut"))
    {
        IsUserLoggingOut = true;
    }
    if (IsUserLoggingOut && SystemManager.CurrentHttpContext.Session != null)
    {
        SystemManager.CurrentHttpContext.Session.Remove("Quote");

        IsUserLoggingOut = false;
    }
}

看起来Sitefinity有自己的SystemManager来访问http上下文。它运作得很好。

相关问题