【发布时间】:2022-02-11 01:45:01
【问题描述】:
我们正在尝试在会话结束时访问会话变量。我们创建了一个名为 ApplicationSessionEventsHandlerModule 的新模块并添加了一个 SessionEnd_Execute 处理程序。
但是,Kentico SessionHelper 类不起作用,System.Web.HttpContext.Current.Session 也不起作用。您如何建议我们在会话结束时访问会话变量?见代码:
public class ApplicationSessionEventsHandlerModule : Module
{
public ApplicationSessionEventsHandlerModule() :
base("ApplicationSessionEventsHandlerModule")
{
}
protected override void OnInit()
{
base.OnInit();
ApplicationEvents.SessionStart.Execute += SessionStart_Execute;
ApplicationEvents.SessionEnd.Execute += SessionEnd_Execute;
}
private void SessionEnd_Execute(object sender, EventArgs e)
{
if (SessionHelper.SessionIsAvailable)
{
if (SessionHelper.GetValue("UserDetails") != null)
{
//Do stuff
}
}
}
private void SessionStart_Execute(object sender, EventArgs e)
{
if (SessionHelper.GetValue("UserDetails") != null)
{
//do stuff
}
}
}
【问题讨论】: