I am trying to clear a HttpContext.Current.Session after User logs out of a Sitefinity page.
I saw in this link that you can check the Request.Url but I'm not exactly sure what the implementation is.
This is my current attempt:
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>();
}
}
Please let me know if you have any tips or suggestions, or if I'm completely wrong with my logic.
Thanks in advance.
UPDATE:
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>();
}
}
}
This is my next attempt at completing the same task but I keep receiving a NullReferenceException...
Note: I've also tried this method in the Application_AcquireRequestState method.
Here is the stack:
[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