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

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

问题描述

是否可以删除Coldfusion服务器上特定应用程序的所有当前会话。我想强制所有用户更新其会话变量并添加新的会话变量。

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设置为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.

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

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