Reputation: 93
I've inherited an old Coldfusion application. This application has a main site and 7 sub sites. The main site, and each sub site, have their own Application.cfc's.
Very much like this example on Adobe site (The graph at the bottom right for Bandwith Associates): https://helpx.adobe.com/coldfusion/developing-applications/developing-cfml-applications/designing-and-optimizing-a-coldfusion-application/structuring-an-application.html
I've built an authentication system that will log a user in at the main level through session variables. However, when they click on or are relocated to any of the sub sites all the session variables disappear. As they should, since Coldfusion doesn't look for any other application.cfc files once it finds one in the current directory where the user is located.
I'm hoping I don't have to go and remove the 7 application.cfc files from each sub site. Because that would involve rewriting every sub site. I just want them to be able to stay logged in (and not have to sign into multiple sub applications.
No code necessary. I just need a high level plan that will work. Ultimately I'll implement it on one sub site to see if it works. If it does, then the I'll implement it on the rest of the sub sites.
The expected result should be for the user to stay logged in through their session regardless of which of the 7 sub sites they go to during the process. They all have same look and feel, and thus its pretty seamless to the end user.
Additional background: This site used to have windows authentication, and now we are going with a typical application login process.
Upvotes: 1
Views: 92
Reputation: 14859
You can have one main Application.cfc
that helps control the rest. Per @Alex's answer, you can just name them all the same Application name, but you may run into situations where certain variables need to be loaded before others. With this approach, only the root Application.cfc
will define the application's name.
Application.cfc
ApplicationProxy.cfc (extends Application.cfc)
/App2/Application.cfc (extends ../ApplicationProxy.cfc
/App3/Application.cfc (extends ../ApplicationProxy.cfc
... etc ...
If your main file load core, shared application
scoped variables, you can have each of the sub files call super.onApplicationStart()
in their own onApplicationStart()
to ensure those variables are loaded if this folder is the first entry point for the application when the server has been restarted.
You can do the same for onSessionStart()
and other functions as needed. I've done this where we updated a code base with over a dozen sub-folder applications that needed to share new global session objects and other data of note.
You can check out Ben Nadel's article on this process.
Upvotes: 1
Reputation: 7833
The session scope can be shared by using the same application name for every Application.cfc or Application.cfm.
Put
<cfset THIS.name = "my_app">
within the body of all your Application.cfc files. (Do not place it inside of a function!)
Use the <cfapplication>
tag
<cfapplication name="my_app">
inside all of your Application.cfm files. Make sure to place the tag before accessing the SESSION scope.
Note: my_app
is obviously just an example. You can use any name, but I suggest you to keep it alphanumeric and less than 32 characters in length. Adobe ColdFusion has some strange bugs when using "exotic" application names.
Upvotes: 2