删除冷融合服务器上的所有会话 [英] Delete all sessions on a coldfusion server

查看:17
本文介绍了删除冷融合服务器上的所有会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法删除冷融合服务器上特定应用程序的所有当前会话.我想强制所有用户更新他们的会话变量并添加新的会话变量.

Is there a way to delete all current sessions for a specific application on a coldfusion server. I want to force all users to renew their session variables and add new session variables.

我想到了类似的东西

<Cfset applicationStop()>

但我不确定它是否会删除所有会话.即便如此,如果确实如此,我仍然需要阻止它删除所有应用程序的所有会话.我只想清除 1 个应用程序的所有会话,并为该网站/应用程序上的所有用户强制执行 OnSessionStart(在 application.cfc 中).

but i am not sure if it deletes all sessions. Even so, if it did i would still need to prevent it to delete all sessions for all applications. I just want to clear all sessions of 1 application and forces the execution of OnSessionStart (in application.cfc) for all users on that website/application.

推荐答案

下面是 Application.cfc 的片段,它允许您重置应用程序的所有会话变量.控制变量是 application.loaded.您需要提供将更改此变量的值以强制会话重新加载的代码. 当您的代码将 application.loaded 设置为 now() 时,它的日期/时间将比 session.loaded 更新,它将重置用户会话.这个版本是用CF2016级别的CFML编写的.

Below is a snippet of an Application.cfc that will allow you to reset all session variables for an application. The controlling variable is application.loaded. You'll need to supply code that will change the value of this variable to force session reloads. When your code sets application.loaded to now(), it will have a date/time newer than session.loaded, it will reset the users session. This version is written in CF2016 level CFML.

此代码更像是一个模板,您必须为您的实现进行修改.

This code is more of a template that you would have to revise for your implementation.

Application.cfc:

component displayname="myApp" {
    this['Name'] = "myApp";
    this['ApplicationTimeout'] = CreateTimeSpan(0, 12, 0, 0);
    this['sessionTimeout'] = CreateTimeSpan(0, 0, 45, 0);
    this['SessionManagement'] = true;
    this['ClientManagement'] = false;
    this['SetClientCookies'] = true;

    public boolean function onApplicationStart() {
        // app variable for session scope refresh
        application['loaded'] = now();

        return true;
    } // onApplicationStart()

    public void function onSessionStart() {
        // this individual session loaded flag
        session['loaded'] = now();

        return;
    } // onSessionStart()

    public boolean function onRequestStart(required string targetPage) {
        // if the applicaiton.loaded variable is more recent, force this session to be reset
        if (application.keyExists("loaded") && session.keyExists("loaded") && application.loaded > session.loaded) {

            // pick one or more of these FOUR options to reset the session.

            // call the J2EE method of invalidating a session
            getPageContext().getSession().invalidate();

            // OR use the CF method
            sessionInvalidate();

            // OR clear the session struct
            session.clear();

            // OR clear important session variables that tell your app that the user is logged out, this will need to change based on YOUR implementation
            session['user'] = "";

            // if you clear the session with a form of invalidate(); onSessionStart() should be called to reset the session.loaded var.  It can also be set here.
            session['loaded'] = now();

            // redirect to the target page, which should send the user back to the login page because the session was reset
            location(url=arguments.targetPage, addtoken=false);
        }

        return true;
    } // onRequestStart()

} // component

当我为网站构建这种系统时,一个奇怪的地方是;尽管调用了 applicationStop(),但会话并没有清除.您会认为应用程序停止时会话会被​​破坏,但事实并非如此.这就是我建立这个方法的原因.会话似乎与单个站点 cookie 相关联,并且独立于它们可能存在的应用程序.

One oddity when I built this kind of system for a site is that; although applicationStop() was called, sessions did not clear. You'd think that sessions would be destroyed when the application was stopped, but they didn't. That's why I built this method. It seemed that sessions are tied to individual site cookies and are independent of the application that they may live in.

这篇关于删除冷融合服务器上的所有会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆