In response to my post about the web.config file in ASP.NET, Ray asked how this was any different from Application.cfm in ColdFusion land. I think that it’s very similar, but there are some things that are better about web.config than Application.cfm.
First, and I think most importantly, web.config is a configuration file and a configuration file only. I’ve seen ColdFusion applications that use Application.cfm for security, some to include the header, some that contain database connection strings, some that contain UDF’s, etc. etc… Application.cfm is more flexible in that sense, but as always, that flexibility comes at the cost of misuse. There is no standard way of providing configuration information to a ColdFusion application.
Second, because web.config contains only XML, you can use your favorite XML parser to create and edit your configuration file. You could programatically generate your configuration file if necessary, while an Application.cfm would require a custom script to be written to first parse the file and then another script to write out the file.
Third, web.config files can be included in multiple directories on an application and inherited. You can include Application.cfm files in multiple directories, but you don’t get inheritance unless you explicitly include the parent level Application.cfm.
Fourth, you can programmaticly access configuration information about the current application without reading web.config. You can’t do this AFAIK in ColdFusion. For instance, let’s say that I have an Application.cfm that includes the following tag:
<cfapplication name=”myApplication” clientmanagement=”Yes” sessionmanagement=”Yes”>
and then somewhere later I wanted to know if sessionmanagement is enabled. How would I do that? Can you? Again, as far as I know, you can’t get that information without parsing the Application.cfm and looking for sessionmanagement=”true”. In ASP.NET, I write a simple line of code:
String sessionMode = Session.Mode;
where Session.Mode has the possible values of Off, Inproc, StateServer, and SQLServer.
I think something like what web.config provides would be a really nice addition to Application.cfm. Maybe Application.cfm just stays as it is and we get Application.config in addition…. maybe it’s better that Application.cfm goes away.
Some comments:
“First, and I think most importantly, web.config is a configuration file and a configuration file only. I’ve seen ColdFusion applications that use Application.cfm for…”
Good point. I could always do that myself in CF, but there is nothing native that says, for Folder X, look for file foo.config or somesuch.
“Second, because web.config contains only XML, you can use your favorite XML parser to create and edit your configuration file. You could programatically generate your configuration file if necessary, while an Application.cfm would require a custom script to be written to first parse the file and then another script to write out the file.”
Well, XML parsing is much easier in MX now so I don’t think this is as much of a big deal. 😉
“Third, web.config files can be included in multiple directories on an application and inherited. You can include Application.cfm files in multiple directories, but you don’t get inheritance unless you explicitly include the parent level Application.cfm.”
Maybe I misread this – but if folder A has an application.cfm, and subfolder AA cfincludes it, and then subfolder AAA includes the application.cfm from AA, then you will get the code from A as well. Doesn’t this fit?
“Fourth, you can programmaticly access configuration information about the current application without reading web.config. You can’t do this AFAIK in ColdFusion. For instance, let’s say that I have an Application.cfm that includes the following tag:”
You can – but it’s not as easy. You don’t have to parse the Application.cfm file – but you can do:
In fact – I wrote a UDF that did this for both sessions and application vars (since they can be turned off in the admin). That being said, a native ‘IsSessionTurnedOn’ would be kind of nice.
” maybe it’s better that Application.cfm goes away.”
Now now, that’s not fair. 😉 I like the fact that I can have a file that gets run before any other. It allows for so many different things for my application. 🙂
>> Well, XML parsing is much easier in MX now so I don’t think this is as much of a big deal. 😉
— My point was that you can parse the web.config file using an XML parser. The Application.cfm is nothing more than a text file with no hierarchy or defined structure, which makes it harder to read from it and write to it.
>> Maybe I misread this – but if folder A has an application.cfm, and subfolder AA cfincludes it, and then subfolder AAA includes the application.cfm from AA, then you will get the code from A as well. Doesn’t this fit?
— My point was that you don’t have to <cfinclude> the web.config down the tree. If you have a web.config at the root of your site and then 4 directories down the tree you have another, you don’t have to include the top level one, the values are inherited, which is nice because you don’t have to worry about pathing issues.
>> ” maybe it’s better that Application.cfm goes away.” Now now, that’s not fair. 😉 I like the fact that I can have a file that gets run before any other. It allows for so many different things for my application. 🙂
— yeah, I like that feature of Application.cfm as well. One of my frustrations in ASP is that I don’t an Application.cfm. Global.asa runs only once. If that’s all we’re using Application.cfm for though, shouldn’t we probably be replace it with a filter? My point was that ColdFusion needs some sort of standard mechanism that stores configuration file variables into the Application scope (or some other persistent scope). I’m sure that this could be done by creating a class that implemented the ServletContextListener interface (http://java.sun.com/webservices/docs/ea2/api/javax/servlet/ServletContextListener.html).