Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7938451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:48:59+00:00 2026-06-03T22:48:59+00:00

I have trouble with setting mappings in Application.cfc We have diverent Server (dev,QS,prod) Each

  • 0

I have trouble with setting mappings in Application.cfc
We have diverent Server (dev,QS,prod)
Each with a little different Pathes.
I want to set serverspecific pathes and variables via configuration file.
On ApplicationStart you read the ini file and setup your system.
http://www.raymondcamden.com/index.cfm/2005/8/26/ColdFusion-101-Config-Files-AGoGo
This works fine.

Normaly you set mappings in Applcation.cfc like this:

<!--- in Application.cfc --->
<cfset this.mappings['/components'] = "D:\Inetpub\wwwroot\myApp\components">

Somewhere in a normal cfm File I instatiate a cfc named test via:

<cfset t = createObject("component", "components.test")>

I want to set the mappings only once at onApplicationsStart

<cffunction
    name="OnApplicationStart"
    access="public"
    returntype="boolean"
    output="false"
    hint="Fires when the application is first created.">

    <!---create structure to hold configuration settings--->
    <cfset ini = structNew()>
    <cfset ini.iniFile = expandPath("./ApplicationProperties.ini")>
    <cfset application.ini = ini>

    <!--- read ini file --->
    <cfset sections = getProfileSections(application.ini.iniFile)>

    <cfloop index="key" list="#sections.mappings#">
       <cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
    </cfloop>

But this don’t work because this.mappings is empty and next request. 🙁

Putting this to OnRequestStart

<!--- read ini file --->
    <cfset sections = getProfileSections(application.ini.iniFile)>

    <cfloop index="key" list="#sections.mappings#">
       <cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
    </cfloop>

I get an error that the component can’t be found.
This is strange.

Putting the struct into Application scope

    <cfloop index="key" list="#sections.mappings#">
       <cfset APPLICATION.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
    </cfloop>

How to call my Component?

<cfset t = createObject("component", "application.components.test")>

Doesn’t work.

So I have 3 targets.

  1. reading all pathes and mappings from ini file
  2. reading them once at ApplicationStart
  3. easy usage in sourcecode.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:49:00+00:00Added an answer on June 3, 2026 at 10:49 pm

    Mappings can’t be set in onApplicationStart(), they must be set in the pseudo constructor of Application.cfc, and they must be set on every request.

    It’s also important to note that the application scope is not available at this point, therefore if you need to cache anything you’ll need to use the server scope. You can cache your mapping struct to the server scope and just set it into this.mappings each request.

    <cfcomponent>
      <cfset this.name = "myapp" />
    
      <!--- not cached so create mappings --->
      <cfif NOT structKeyExists(server, "#this.name#_mappings")>
        <cfset iniFile = getDirectoryFromPath(getCurrentTemplatePath()) & "/ApplicationProperties.ini" />
        <cfset sections = getProfileSections(iniFile) />
        <cfset mappings = structnew() />
        <cfloop index="key" list="#sections.mappings#">
          <cfset mappings[key] = getProfileString(iniFile, "mappings", key)>
        </cfloop>
        <cfset server["#this.name#_mappings"] = mappings />
      </cfif>
    
      <!--- assign mappings from cached struct in server scope --->
      <cfset this.mappings = server["#this.name#_mappings"] />
    
      <cffunction name="onApplicationStart">
      <!--- other stuff here --->
      </cffunction>
    
    </cfcomponent>
    

    If you intend to keep you ini file in the webroot, you should make it a .cfm template and start it with a <cfabort>. It will work just the same but will not be readable

    ApplicationProperties.ini.cfm

    <cfabort>
    [mappings]
    /foo=c:/bar/foo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble accessing filestream via SqlFileStream. Sql server and IIS7 are on different
I am having trouble setting up jpa mappings for some entities. I have a
Im having a little trouble setting up routes. I have a 'users' controller/model/views set
I am having trouble setting up landscape mode in my application. I have a
I have a ZendX_Jquery_Form where I am having a trouble setting placeHolder for a
I have some trouble setting up Tramp with EmacsW32 and cygwin. I have configured
I am having a little trouble setting the height of an element that I
I have some trouble on setting of n-linear equations in matlab.I don't know how
I'm having some trouble getting the hang of HQL. I have an application where
I'm migrating to Nhibernate 2.0 GA but have some trouble with setting cache expirations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.