我们正在尝试访问会话结束时的会话变量。我们创建了一个名为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
}
}
}发布于 2022-02-10 17:45:01
请试以下几点-
下创建全局文件夹
使用CMS.Base;使用CMS.DocumentEngine;使用CMS.Helpers;使用CMS.Membership;ApplicationSessionEventsHandler公共部分类CMSModuleLoader {公共类ApplicationSessionEventsHandler : CMSLoaderAttribute { public覆盖void (){ ApplicationEvents.SessionEnd.Execute += SessionEnd_Execute;ApplicationEvents.SessionStart.Execute += SessionStart_Execute;SessionStart_Execute(对象发送方,System.EventArgs e) { if (SessionHelper.GetValue("UserDetails") != null) { //do }}私有空洞SessionEnd_Execute(对象发送方,System.EventArgs e) { if (SessionHelper.SessionIsAvailable) { if (“UserDetails”) != null) { //Do }
https://stackoverflow.com/questions/71056403
复制相似问题