Session Sitefinity-注销后删除会话
我正在尝试在用户注销Sitefinity页面后清除HttpContext.Current.Session 我在这里看到,您可以检查Request.Url,但我不确定实现是什么 这是我目前的尝试:Session Sitefinity-注销后删除会话,session,global-asax,sitefinity,Session,Global Asax,Sitefinity,我正在尝试在用户注销Sitefinity页面后清除HttpContext.Current.Session 我在这里看到,您可以检查Request.Url,但我不确定实现是什么 这是我目前的尝试: protected void Application_AuthenticateRequest(object sender, EventArgs e) { if (((System.Web.HttpApplication)(sender)).Request.Url.ToString() == Ht
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>();
}
}
这与我的做法非常接近。我要做的唯一更改是将url比较逻辑更改为:
if (((System.Web.HttpApplication)(sender)).Request.Url.ToString().EndsWith("/Sitefinity/Login/DoLogout"))
或者可能使用.Contains()而不是EndsWith()--不确定DoLogout操作上是否添加了任何查询字符串参数或尾部斜杠
这是因为Request.Url返回一个Url(例如),而Server.MapPath()返回一个本地路径(例如C:\inetpub\wwwroot\whatever),所以如果比较这两个路径,就不会对苹果进行比较
编辑:
类似的方法应该可以工作,只需添加一个检查来查看会话是否为null
protected void Application_PostAcquireRequestState(object sender, EventArgs e)
{
if (((HttpApplication)(sender)).Request.Url.ToString().Contains("sign_out=true"))
{
if (HttpContext.Current.Session != null && HttpContext.Current.Session["Cart"] != null)
{
HttpContext.Current.Session.Remove("Cart");
HttpContext.Current.Session["Cart"] = new List<IQuoteResult>();
}
}
}
受保护的无效应用程序\u PostAcquireRequestState(对象发送方,事件参数e)
{
if(((HttpApplication)(sender)).Request.Url.ToString()包含(“sign_out=true”))
{
if(HttpContext.Current.Session!=null&&HttpContext.Current.Session[“购物车”]!=null)
{
HttpContext.Current.Session.Remove(“购物车”);
HttpContext.Current.Session[“购物车”]=新列表();
}
}
}
这就是我的解决方案:
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上下文。它工作得非常好。因此,事实证明,会话可以在应用程序中访问\u authenticateRequest。我已经用一些新代码和错误堆栈跟踪进行了更新。。不确定您是否能知道null引用异常发生在哪里?它是Request.Url吗?还是HttpContext.Current.Session?无论哪种方式,我都会调试它,找出哪个是空的,然后添加一个'!=这是会话,因为我删除了Request.Url IF语句,只检查了会话是否正确!=谢谢你的帮助。我以前看过那个帖子。我认为sitefinity有点古怪。
protected void Application_PostAcquireRequestState(object sender, EventArgs e)
{
if (((HttpApplication)(sender)).Request.Url.ToString().Contains("sign_out=true"))
{
if (HttpContext.Current.Session != null && HttpContext.Current.Session["Cart"] != null)
{
HttpContext.Current.Session.Remove("Cart");
HttpContext.Current.Session["Cart"] = new List<IQuoteResult>();
}
}
}
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;
}
}