如何在服务器/同一域下的多个ColdFusion应用程序之间共享一个SESSION? [英] How can I share a SESSION between multiple ColdFusion applications on the server/under the same domain?

查看:146
本文介绍了如何在服务器/同一域下的多个ColdFusion应用程序之间共享一个SESSION?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 https:// sub。上有一个域sub.domain.com,其中有一个登录表单。 domain.com/login.cfm

在根目录中,我有Application.cfc,它使用 THIS .Name =MyApp;

In the root directory, I have my Application.cfc which names the application using THIS.Name = "MyApp";.

我在这个网站上有几个子目录,我想作为单独的应用程序运行,它们自己的Application.cfc,它扩展了根Application.cfc,但是每个都有自己的名称,因此我可以创建该应用程序唯一的应用程序范围变量:

I have several sub-directories on this website, which I want to run as separate applications, with their own Application.cfc which extends the root Application.cfc, but each has it's own name, so that I can create Application-scope variables unique to that application:

实例: sub.domain.com/site1/Application.cfc

扩展 sub.domain.com/Application.cfc (使用Proxy cfc)
THIS.Name =MyApp_Site1;

一些应用程序特定的应用程序范围变量。

and sets some Application-scope variables specific to the application.

但是,当他们登录 https://sub.domain.com/login.cfm ,那里设置的任何SESSION范围变量都绑定到APPLICATION名称MyApp。

But, when they login in at https://sub.domain.com/login.cfm, any SESSION-scope variables set there are tied to the APPLICATION name "MyApp".

我可以使用什么类型的解决方案来接受根目录应用程序中的有效登录,然后将用户转发到其应用程序,同时继承其用户特定属性?

What kind of solution can I use to accept the valid login in the root directory Application, and then forward the user to their application, while carrying over their user-specific properties?

推荐答案

正如@Dave Ferguson提到的,最简单的方法,最冷的方式来共享会话数据是保持为单一应用。您甚至可以将内容放在不同的文件夹中,只要名称相同。

As @Dave Ferguson mentioned, the easiest way, most coldfusiony way to share the session data is to keep it as a single application. You could even have the contents in a different folder, as long as the names are the same.

您不需要使用像FW\1这样的框架,就可以得到你想要的东西,虽然他们可能会更容易。您可以始终将结构存储在应用程序范围内,键是子应用程序名称。例如application.myvariable可以来自application [request.subappname] .myvariable。这使您有一个应用程序,但应用程序变量的作用域为各种子应用程序。

You don't need to use a framework like FW\1 or anything like that to get what you're looking for, although they may make it a bit easier. You can always store structs inside the application scope, with the key being the the sub-application name. For example application.myvariable could be come application[request.subappname].myvariable. This keeps you with one application, but the application variables are scoped for the various sub-applications. You can do the same with your session variables too.

另一种方法,如@Brian所提到的,将使用一个中介商店。然后,您可以使用任何所需的密钥存储会话数据。正如@Dave Ferguson提到的,将您的CFID和CFTOKEN设置为域Cookie(CF10尤其在设置Cookie )。这样,相同的CFID和CFTOKEN将在应用程序之间使用。它们仍然具有不同的会话,但使用相同的会话标识符。然后,您可以使用该组合作为您在中间商店中的数据的键。

Another approach, as @Brian mentioned, would use an intermediary store. You could then store your session data using any key you want. As @Dave Ferguson mentioned, set your CFID and CFTOKEN as domain cookies (CF10 in particular has some improvements in setting up the cookies). That way the same CFID and CFTOKEN will be used across applications. They still have different sessions, but use the same session identifiers. You can then use that combination as the key to your data in the intermediary store.

数据库将是常规的方式,但根据您的应用程序可能导致并发和锁定问题,序列化/反序列化的问题或性能,然后总是处理旧/过期数据的清除。因此,您可能需要查看类似 ehcache memcached 来处理此问题。

A database would be the conventional way to go about this, but depending on your app this may cause concurrency and locking issues, issues with serialization/deserialization, or performance, and then there's always handling the purging of old/expired data. So you might want to look into something like ehcache or memcached to handle this.

ehcache是​​一个有吸引力的选项,因为它与ColdFusion 9+捆绑在一起,和磁盘,根据您的设置,缓存中的数据可以在服务重新启动(或重新启动)后生存,并且可以设置为在一定数量的不活动后自动使记录过期。是的,它可以用于自定义缓存

ehcache in particular is an attractive option, as it is bundled with ColdFusion 9+, can use both memory and disk, depending on your settings, the data in the cache can survive a service restart (or reboot), and it can be set to automatically expire records after a certain amount of inactivity. And yes, it can be used for custom caches.

我建议你小心,如果你采取这种方法。你需要权衡每次(从onRequestStart)抓取缓存中的数据的性能命中,通过获取onSessionStart()中的数据并在多个应用程序中保持重复数据,直到会话超时,来评估内存消耗。你去哪条路线完全取决于应用程序的性能特点,会话数据的大小等。

I do advise that you be careful if you take this approach. You need to weigh the performance hit for grabbing the data from the cache each time (say in onRequestStart), vs the memory consumption by grabbing the data in onSessionStart() and holding duplicates across many applications, until the session(s) time out. Which route you go will depend totally on the performance characteristics of your application, size of your session data, etc.

这篇关于如何在服务器/同一域下的多个ColdFusion应用程序之间共享一个SESSION?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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