Application.cfc, OnRequestStart, CFInclude

O.K. I'll admit I am feeling a little stupid here but I just
don't understand this. All I wanted to do was include my script
library file using the OnRequestStart function withn
application.cfm. There isn't anything special inthe _ScriptLib.cfm
template. My Application.cfc file looks like this... (Only the
pertinent portions are included)
<CFFUNCTION NAME="onRequestStart" OUTPUT="Yes"
RETURNTYPE="any">
<CFINCLUDE TEMPLATE="_ScriptLib.cfm">
... (other CFSETS and junk like that)
</CFFUNCTION >
<CFFUNCTION NAME="onRequest">
<CFARGUEMENT NAME="targetTemplate" type="String"
required="true" />
<CFINCLUDE TEMPLATE="#arguments.targetTemplate#">
</CFFUNCTION>
My question is why do I need to add the CFArguement tag in
the OnRequest function to include my scripts??? Why doesn't the
CFInclude tag in OnReq

My question is why do I need to add the CFArgument tag in the
OnRequest function to include my scripts???
You don't need to add the cfargument tag to onRequest to
enable you to use cfinclude in OnRequestStart. In this case, the
only musts are:
if you implement the OnRequest method, then it must load the
target-page through a cfargument tag and it must explicitly call
the page through a cfinclude tag.
That makes the Variables scope of the requested page (and its
included pages!) available in OnRequestStart. If a variable is
called x in the requested page, you may just call it x in
OnRequestStart. If you hadn't included the cfargument and cfinclude
tags in OnRequest, or if you didn't iimplement the OnRequest method
at all, the only page variables you would have access to in
OnRequestStart are those in Request scope.

Similar Messages

  • Issues with data returned on application.cfc onRequeststart

    I have a shopping cart that works from main code with VD on IIS.
    So all the code is places in one directory, and for each store I create a Virtual directory on the IIS
    so a store link will look like this :
    www.shoppingcart.com/store/XXXXX
    when the xxx is the prefix of that store.
    in the application.cfc ONREQUERSTSTART I take the last part of the URL and match it with the PREFIX I in the list of stores on the DB.
    to get the prefix I do this :
    <cfset request.store.prefix = "#listgetat(cgi.SCRIPT_NAME,listlen(cgi.SCRIPT_NAME,'/')-1,'/')#">
    Then to get the right store info I used to do this :
    <cfset qreadStoreInfo = application.cfc.StoreDetails.read(filterStorePrefix request.store. prefix)>
    It all worked well (for over 4yrs) till about 2-3 moths ago (or at least then one of the client complained) when we start seeing the WRONG output of store info, like stores were "mixed" some how – totally randomly.
    After following it for a few days I noted that the query that is returned from the CFC is for the wrong store.
    At first I thought it’s the request.store.prefix not "stored" by the time I get to the query line so I changed this :
    <cfset qreadStoreInfo = application.cfc.StoreDetails.read(filterStorePrefix= "#listgetat(cgi.SCRIPT_NAME,listlen(cgi.SCRIPT_NAME,'/')-1,'/')#")>
    Yet I still get the wrong value back from the Query, and when looking at the Query I can see that the VALUE been sent in is wrong, even that I know for sure that I sent in the right value, since in the email I do an out put of the info on the page.
    Did any one encountered any thing like this before ?
    Any leads on how to maybe start handling ?
    Is there a way that if the client is looking at 2 site at the same time thus queries can get "mixed", even that they are done on the ONREQUEST part of the application.cfc (IE each page should be processed on its own)

    talofer99 wrote:
    www.shoppingcart.com/store/XXXXX
    when the xxx is the prefix of that store.
    in the application.cfc ONREQUERSTSTART I take the last part of the URL and match it with the PREFIX I in the list of stores on the DB.
    to get the prefix I do this :
    <cfset request.store.prefix = "#listgetat(cgi.SCRIPT_NAME,listlen(cgi.SCRIPT_NAME,'/')-1,'/')#">
    That wont get you the prefix, I'm afraid. You want the last list element. To get it, you could use
    <cfset request.store.prefix = listgetat(cgi.SCRIPT_NAME,listlen(cgi.SCRIPT_NAME,'/'),'/')>
    or, even better,
    <cfset request.store.prefix = listLast(cgi.SCRIPT_NAME,'/')>

  • Contribute and Application.cfc

    I'm building out a site that is contribute-ready, and also
    makes use of Coldfusion MX 7's Application.cfc page. The
    application.cfc page has an onRequestStart function that
    <cfincludes> the navigational elements. When I drop into edit
    mode for a page, the navigational elements disappear. This wouldn't
    be a problem, except that the link to the site style sheet is part
    of one of the <cfincludes>. So, my Contribute users can't
    make use of the site stylesheet, and can't see the page they're
    editing in the context of the navigational elements.
    Strangely enough, if I move the navigational elements out of
    the Application.cfc and <cfinclude> them directly on the
    individual pages, Contribute has no problem displaying them when in
    edit mode.
    Why would Contribute exclude Application.cfc when in edit
    mode, and is there a way to fix this?
    Thanks,
    Michael

    Hi Greg,
    No, I never got a response to this from Adobe, and wasn't
    able to get the site to work with Contribute unless I kept the
    <cfincludes> within the individual pages. Sorry I couldn't be
    more help, but let me know if you have better luck.
    Thanks,
    Michael

  • Application.cfc and UDFs

    I have some UDFs that i want to make available to every page
    in my site woudl i just drop the code for those UDFs inside the
    onRequestStart method of application.cfc?

    In article <f8vi12$9q8$[email protected]>
    "bdee2"<[email protected]> wrote:
    > I have some UDFs that i want to make available to every
    page in my
    > site woudl i just drop the code for those UDFs inside
    the
    > onRequestStart method of application.cfc?
    Probably the simplest approach for you is to put those UDFs
    in some
    cfm file and then include that into onRequest():
    <cffunction name="onRequest">
    <cfargument name="targetPage"/>
    <cfinclude template="myudfs.cfm" />
    <cfinclude template="#arguments.targetPage#" />
    </cffunction>
    Note: you must include the target page - onRequest() assumes
    you are
    taking full responsibility for the request.
    Only when you use onRequest() will the VARIABLES scope of
    Application.cfc be accessible inside your top-level page
    (arguments.targetPage).
    Note: if you use Flash Remoting, Web Services or direct AJAX
    CFC
    calls, you cannot use onRequest() directly (because it
    intercepts the
    result). Read the chapter on Application.cfc in the
    ColdFusion
    Developer's Guide (it's really very good reading!). You might
    also
    want to read this blog entry:
    http://corfield.org/entry/Applicationcfc__onRequest_and_CFCs
    And this LiveDocs page:
    http://livedocs.adobe.com/coldfusion/7/htmldocs/00000698.htm
    (which includes the workaround for and onRequest() and CFC
    access)
    Sean Corfield
    An Architect's View --
    http://corfield.org/
    I'm using an evaluation license of nemo since 59 days.
    You should really try it!
    http://www.malcom-mac.com/nemo

  • What's wrong with my Application.cfc file

    I've decided to convert an old app from using Application.cfm to Application.cfc, mainly because I want to use onRequestStart and the like, and I can't get them to initialize in Application.cfm.
    But for some reason, this Application.cfc file causes my pages to come up blank.  I can't for the life of me figure out why, since it's copied from an app that works perfectly fine.
    <cfcomponent>
        <cfset this.name = "myapp">
        <cfset this.sessionManagement = true>
        <cfset this.sessionTimeout = CreateTimeSpan(0,2,0,0)>
        <cfset this.loginStorage="session">
        <cfset this.scriptProtect = true>
        <cfset this.setclientcookies = false>
        <cffunction name="onApplicationStart">
            <cfset application.dsource = "mydsn">
            <cfset application.appid = "123456">
            <cfset application.appname = "myappname">
        </cffunction>   
        <cffunction name="onSessionStart">
            <cfparam name="session.trackingno" default="0">
            <cfparam name="session.emailaddr" default="">
            <cfparam name="session.newitem" default="1">
            <cfparam name="session.authserver" default="">
            <cfparam name="session.id" default="">
            <cfparam name="session.rights" default="">
            <cfparam name="session.userid" default="">
            <cfparam name="session.sauth" default="">
            <cfparam name="session.creds" default="">
        </cffunction>
          <cffunction name="onRequest" output="true">   
            <cfinclude template="/planning/application.cfm">   
            <cfinclude template="/planning/tpea/2015/validate.cfm">
          </cffunction>
    </cfcomponent>
    What have I done wrong?

    What is in the two templates you are including inside your onRequest() function?  Do they actually output any content?
    You don't have the actual requested page being included.  You need to add an argument to the top of the function to receive the requested page:
    <cfargument name="TargetPage" type="string" required="true">
    Then you need to add another <cfinclude> to include that page:
    <cfinclude template="#arguments.TargetPage#" />
    You'll have to figure out if that include should come before or after your existing includes.
    -Carl V.

  • Updating application to use Application.cfc

    I have an application that is using the older style
    application.cfm for setting up configuration varibles like DSN and
    what not. Of course this way i can just use the varibles as is like
    #dsn#.
    I am wanting to change my application over to utilize
    Application.cfc instead now. It seems to set up my DSN efficiently
    i would set this varible up in the onApplicationStart or
    onRequestStart. Either way I have to now state my varibles as
    #application.dsn# to make them work now.
    Is there anyway around this so I dont have to change hundreds
    of varibles names!

    Implement
    <cffunction name="onRequest">
    <cfargument name = "targetPage" type="String"
    required=true/>
    <cfsavecontent variable="content">
    <cfinclude template="#Arguments.targetPage#">
    </cfsavecontent>
    <cfoutput>#content#</cfoutput> <!---
    requested page content --->
    </cffunction>
    You can then change gear in onRequestStart with:
    <cfset dsn = application.dsn>
    In fact, you can forget about application.dsn and do the
    following in onRequestStart:
    <cfset dsn = "myDSN">

  • Work around for Application.cfc

    I have an Application.cfc file that outputs a header and footer page for every request.  That works wonderful but if I try to open a page that is doing a <cfgrid> using a CFC file than I get an error of "Error invoking CFC /GATS/CFC/purchaseOrder.cfc : Internal Server Error [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]" when opening the page.
    Commenting out the header/footer include in the Application.cfc file lets the <cfgrid> populate with the CFC file.  Is there a fix or work around for this?
    Application.cfc file
    <cfcomponent output="false">
    <cffunction name="onRequestStart" returnType="boolean" output="true">
          <cfargument name="thePage" type="string" required="yes">
         <cfset PageName = GetFileFromPath(thePage)>
        <cfif not IsDefined("session.user.isAuthenticated") or
              session.user.isAuthenticated equal session.no>
          <cfif FindNoCase('index.cfm', PageName) is not 0>
            <cfelse>
              <cfset session.messages[1] = "Authentication required.">
              <cflocation url="#application.WebAddress#" addtoken="no">
          </cfif>
        </cfif>
        <cfif FindNoCase('index.cfm', PageName) is not 0>
          <cfset request.PageNavigation = "">
          <cfset request.Screen = "Login">
        </cfif>
        <cfif FindNoCase('mainMenu.cfm', PageName) is not 0>
          <cfset request.PageNavigation = "Home">
          <cfset request.Screen = "">
        </cfif>
        <cfif FindNoCase('purchaseOrder.cfm', PageName) is not 0>
          <cfset request.PageNavigation = '<a href="mainMenu.cfm">Home</a> &##8226; New Purchase Order'>
          <cfset request.Screen = "">
        </cfif>
        <cfif FindNoCase('logout.cfm', PageName) is not 0>
          <cfelse>
            <cfinclude template="includes/header.cfm">
        </cfif>
        <cfreturn true>
      </cffunction>
    <cffunction name="onRequestEnd" returnType="void" output="true">
          <cfargument name="thePage" type="string" required="yes">
        <cfset PageName = GetFileFromPath(thePage)>
        <cfif FindNoCase('logout.cfm', PageName) is not 0>
          <cfelse>
            <cfinclude template="includes/footer.cfm">
        </cfif>
      </cffunction>
    </cfcomponent>
    purchaseOrder.cfm
    <cfgrid name="AccountGrid" format="html" bind="cfc:GATS.CFC.purchaseOrder.GetQuantities({cfgridpage},{cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdirection})">
      <cfgridcolumn name="ID" header="ID" display="yes">
      <cfgridcolumn name="vendor_name" header="Name" display="yes">
    </cfgrid>
    I found this on the web:
    That error is due to our application.cfm having a single HTML comment at the
    start of the file. Apparently if your Application.cfm or Application.cfc file
    outputs ANYTHING, binds to CFCs with AJAX (via HTML CFGRID or CFAJAXPROXY, for
    example) do not work. The CFC will be called, but the data from it will never
    "flow" into the CFGRID. Removing the comment from the Application.cfm file took
    care of our CFGRID issue.
    This there a way to have an Application.cfc file that displays a header and footer for every page and have and
    have a page have a <cfgrid> in it?

    BKBK,
    I created the examples you posted and commenting out the header/footer lines in my Application.cfc displayed the cfgrid results (updating the query to a table I had).  Running the same example code with the header/footer included in the Application.cfc would not show the cfgrid results.
    I attached the Application.cfc file for review.
    Couldn't attach the file.
    Application.cfc
    <cfcomponent output="yes">
      <cfset this.name = "GATS">
      <cfset this.clientmanagement = "true">
      <cfset this.applicationtimeout = CreateTimeSpan("0","0","20","0")>
      <cfset this.sessionmanagement = "true">
      <cfset this.sessiontimeout = CreateTimeSpan("0","0","20","0")>
      <cfset this.scriptProtect = "true">
      <cfparam name="session.yes" default="Yes">
      <cfparam name="session.no" default="No">
      <cffunction name="onApplicationStart" returnType="boolean" output="no">
        <cfset application.Directory = "/GATS/">
        <cfset application.Datasource = "IA-webapplications">
        <cfset application.DatasourceGATS = "SBS-GATS">
        <cfreturn true>
      </cffunction>
      <cffunction name="onApplicationEnd" returntype="void" output="no">
        <cfargument name="ApplicationScope" required="yes" />
      </cffunction>
      <cffunction name="onSessionStart" returntype="void" output="no">
        <cflock scope="session" timeout="5" type="exclusive">
          <cfset session.no = "No">
          <cfset session.yes = "Yes">
          <cfset session.new = "New">
          <cfset session.user = StructNew()>
          <cfset session.user.isAuthenticated = session.no>
          <cfset session.user.emplid = ""> 
          <cfset session.user.userSSOId = "">
          <cfset session.user.firstName = "">
          <cfset session.user.lastName = "">
          <cfset session.user.name = "">
          <cfset session.messages = ArrayNew(1)>
          <cfset session.savedInputValues = ArrayNew(1)>
          <cfset session.filesTransferred = "">
        </cflock>
      </cffunction>
      <cffunction name="onSessionEnd" returntype="void" output="no">
        <cfargument name="SessionScope" required="yes">
        <cflock scope="session" timeout="5" type="exclusive">
          <cfset Arguments.SessionScope.user.isAuthenticated = session.no>
          <cfset Arguments.SessionScope.users.emplid = ""> 
          <cfset Arguments.SessionScope.user.userSSOId = "">
          <cfset Arguments.SessionScope.user.firstName = "">
          <cfset Arguments.SessionScope.user.lastName = "">
          <cfset Arguments.SessionScope.user.name = "">
        </cflock>
      </cffunction>
      <cffunction name="onRequestStart" returntype="void" output="yes">
        <cfargument type="String" name="TargetPage" required="yes">
        <cfset PageName = GetFileFromPath(TargetPage)>
        <cfif not IsDefined("session.user.isAuthenticated") or
              session.user.isAuthenticated equal session.no>
          <cfif FindNoCase('index.cfm', PageName) is not 0>
            <cfelse>
              <cfset session.messages[1] = "Authentication required.">
              <cflocation url="#application.WebAddress#" addtoken="no">
          </cfif>
        </cfif>
        <cfif FindNoCase('index.cfm', PageName) is not 0>
          <cfset request.PageNavigation = "">
          <cfset request.Screen = "Login">
        </cfif>
        <cfif FindNoCase('mainMenu.cfm', PageName) is not 0>
          <cfset request.PageNavigation = "Home">
          <cfset request.Screen = "">
        </cfif>
        <cfif FindNoCase('purchaseOrder.cfm', PageName) is not 0>
          <cfset request.PageNavigation = '<a href="mainMenu.cfm">Home</a> &##8226; New Purchase Order'>
          <cfset request.Screen = "">
        </cfif>
        <cfif FindNoCase('logout.cfm', PageName) is not 0>
          <cfelse>
            <cfinclude template="includes/header.cfm">
        </cfif>
      </cffunction>
      <cffunction name="onRequestEnd" returntype="void" output="yes">
        <cfargument type="String" name="TargetPage" required="yes">
        <cfset PageName = GetFileFromPath(TargetPage)>
        <cfif FindNoCase('logout.cfm', PageName) is not 0>
          <cfelse>
            <cfinclude template="includes/footer.cfm">
        </cfif>
        <cfif FindNoCase('sessionTerminated.cfm', PageName) is not 0>
          <cfinvoke method="onSessionEnd">
            <cfinvokeargument name="SessionScope" value="#session#">
          </cfinvoke>
        </cfif>
      </cffunction>
      <cffunction name="onError" returnType="void" output="no">
        <cfargument name="exception" required="true">
        <cfargument name="eventName" type="string" required="true">
        <cfthrow object="#arguments.exception#">       
      </cffunction>
    </cfcomponent>

  • Tracking users in the Application.cfc, please help

    Hello;
    I wrote a small tracking system for my web site. I am trying
    to upfrade it to work in CF 8. Here is what I am doing.
    I had this code on the index.cfm page of my site. I am
    attempting to move it to the Application.cfc file. When I do, it
    registers in the DB every time the user hits a page or clicks a
    link. I don't want it to do that. I do want it to tell me when they
    hit the site, and if I can what page they came in on.
    Here is my code:
    <cfquery name="tracking" datasource="my-DB"
    dbtype="ODBC">
    INSERT INTO tracking (REMOTE_ADDR, HTTP_USER_AGENT,
    TRACK_DATE, PageID)
    VALUES('#REMOTE_ADDR#', '#HTTP_USER_AGENT#',
    #CreateOdbcDateTime(now())#)
    </cfquery>
    My pageID is where I want the information on what page the
    user came in on to go.
    I placed teh query inside a session function code, but it
    doesn't work at all right now, I need to limit the hits counted by
    the Application.cfm, if I place it inside the area of the app that
    is for global variables, it adds info to the DB everytime they
    click a link and I don't want that. As for the entry page of the
    user, I am trying to make it so if someone enters the site lets say
    on the about.cfm page, that is added to the db and so on. Is this
    possible? If so how would I do that?
    Here is my application.cfc code so far:
    <cfcomponent output="false">
    <cfset THIS.name = "my-web">
    <cfset this.sessionManagement="yes">
    <cfset this.clientManagement=true>
    <cffunction name="onApplicationStart" returntype="boolean"
    output="false">
    <cfset APPLICATION.appStarted = now()>
    <cfreturn true>
    </cffunction>
    <cffunction name="onApplicationEnd" returntype="void"
    output="false">
    <cfargument name="appScope" required="True">
    <cflog file="#THIS.name#" text="App ended after
    #dateDiff('n' , ARGUMENTS.appscope.appStarted,now())# minutes.">
    </cffunction>
    <cffunction name="onSessionStart" returntype="query"
    output="true">
    <cfquery name="tracking" datasource="creative"
    dbtype="ODBC">
    INSERT INTO tracking (REMOTE_ADDR, HTTP_USER_AGENT,
    TRACK_DATE)
    VALUES('#REMOTE_ADDR#', '#HTTP_USER_AGENT#',
    #CreateOdbcDateTime(now())#)
    </cfquery>
    </cffunction>
    <cffunction name="onRequestStart" returntype="boolean"
    output="true">
    <cfset request.datasource = "my-db">
    <cfset sitePath = "
    http://www.myweb">
    <!--- this is where I was putting the tracking code and it
    added to the DB everytime someone clicked a link. not what I want
    --->
    <!--- Start True Url Variables --->
    <cfloop
    list="#removeChars(cgi.path_info,1,len(cgi.script_name))#"
    delimiters="/" index="variableSet">
    <cfscript>
    variableName = "url." & listGetAt(variableSet,1,'.');
    expression = listGetAt(variableSet,2,'.');
    </cfscript>
    <cfparam name="#variableName#" default="#expression#">
    </cfloop>
    <!--- Finish True Url Variables --->
    <cfreturn true>
    </cffunction>
    </cfcomponent>
    Thank you.
    Phoenix

    I did a dump and got it to error out, so it is recognizing
    the session, but it doesn't add any info to the DB. I also had to
    change it, I had it like this:
    <cffunction name="onSessionStart" returntype="query"
    output="true">
    <cfquery name="tracking" datasource="my-db"
    dbtype="ODBC">
    INSERT INTO tracking (REMOTE_ADDR, HTTP_USER_AGENT,
    TRACK_DATE)
    VALUES('#REMOTE_ADDR#', '#HTTP_USER_AGENT#',
    #CreateOdbcDateTime(now())#)
    </cfquery>
    </cffunction>
    Changed it to this:
    <cffunction name="onSessionStart" returntype="any"
    output="true">
    <cfquery name="tracking" datasource="creative"
    dbtype="ODBC">
    INSERT INTO tracking (REMOTE_ADDR, HTTP_USER_AGENT,
    TRACK_DATE)
    VALUES('#REMOTE_ADDR#', '#HTTP_USER_AGENT#',
    #CreateOdbcDateTime(now())#)
    </cfquery>
    </cffunction>
    it was erroring on the query attribute before in the session
    function. Even that change didn't get it to work properly.

  • Moving to CF10, Need help with Application.cfc

    I've been googling about how to work with Application.cfc since last week but I still have some questions and I can't find the answers.
    My application is under the root (in unix) and there are many subfolders underneath it. Each sub-folder is hosting a different web application.
    From what I read, I can create 1 root Application.cfc and then on subsequent sub-folder, when I need to have another Application.cfc on that level, I can create ProxyApplication (see below) and then create a sub-folder level Applicatin.cfc
    So, when I set an application.DSN on my root Application.cfc, using proxyApplication I don't have to reset this dsn again in my sub folder level Application.cfc
    Since my loginform.cfm and loginaction.cfm is right under root directory too,  I also set OnsessionStart in the root Application.cfc to handle user login. Then this means, I don't have to reset session variable again anywhere because session.username, etc has been set on the highest level.
    Is this correct?
    In addition, Am I correct when I do the following:
    1. Since I have root level and sub-folder level Application.cfc, I should set this.name with a different name, am I right?
        On the root Application.cfc I set this.name = "StudentServices" because this represent the global application
        On the sub-folder level's Application.cfc, I set this.name to "StudentServices_stdLoad" becaus this sub-folder only handle student load application.
    2. On the root Application.cfc, I set the DSN to the application scope. So on the sub-folder level Application.cfc I can check if a particular db is working or not
        because as awhole, in the global sense, this web application uses more than one Databases. Each sub-folder may use a database that is dfferent than the other sub folder.
    Am I doing the right thing? Please advice
    Below is example of what I have, Thank you!
    I created a root Application.cfc under the root directory: 
    <CFCOMPONENT displayname="Application" output="true" hint="My Root Application component">
       <!--- Set up the application --->    <cfset THIS.Name = "StudentServices" />    <cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />    <cfset THIS.SessionManagement = true />    <cfset THIS.SetClientCookies = false />
           <cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false">
       <cfset application.MainDSN = "DSN1">
       <cfset application.ReportDSN = "DSN2">
       <cfreturn true/>
    </cffunction>
     <cffunction name="onApplicationEnd" output="false">
         <cfargument name="applicationScope" required="true">  </cffunction>
     <cffunction name="onSessionEnd">
    </CFCOMPONENT>
    Then, in this root directory I also created a ProxyApplication:
     <!--- it's empty and it Serves merely to create an alias for your root /Application.cfc --->
     <cfcomponent name="ApplicationProxy" extends="AdvancementServices.Application"> 
    </cfcomponent>
    Then in the Sub-Directory, I can create a sub-folder level Application.cfc extending the root Application.cfc:
     <CFCOMPONENT displayname="Application" extends="ApplicationProxy">
        <!--- Set up the sub-folder application --->
        <cfset THIS.Name = "StudentServices_stdLoad"/> 
        <cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) /> 
        <cfset THIS.SessionManagement = true/> 
        <cfset THIS.SetClientCookies = false/> 
        <cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false">
           <!--- ****** Testing whether the ADVUPGRD is accessible by selecting some data.****** --->
           <cftry>
           <cfquery name="TestMain_DSN" datasource="#application.MainDSN#" maxrows="2">
             SELECT Count(*)          FROM MyTable
           </cfquery>
             <!--- If we get a database error, report an error to the user, log the error information, and do not start the application. --->
            <cfcatch type="database">
              <cflog file="#this.name#" type="error" text="Main DSN is not available. message: #cfcatch.message# Detail: #cfcatch.detail# Native Error: #cfcatch.NativeErrorCode#" >
             <cfthrow message="This application encountered an error when connecting to the Main Database. Please contact support." />
             <cfreturn false>
           </cfcatch>
         </cftry>
         <cflog file="#this.name#" type="Information" text="Application #this.name# Started">
         <cfreturn true/>
       </cffunction>
    </CFCOMPONENT>
        <cfargument name = "SessionScope" required=true/>     <cfargument name = "AppScope" required=true/>
    </cffunction>
    <cffunction name="OnSessionStart" access="public" returntype="void" output="false"> 
      <CFSET session.UserGroup = ""/> 
      <CFSET session.UserName = ""/> 
      <CFSET session.currentPage = ""/> 
      <CFSET session.loggedin = "No"/> 
      <CFSET session.userrights = ""/>
      <cfreturn/>
    </cffunction>

    OK.  It sounds to me like you really shouldn't be using a single root Application.cfc at all, if all you want to do is share some settings between your "sub-applications".  I would look at storing the common settings in an external file that all of the applications can read in.  The simplest way is to put the settings in a .CFM file somwhere outside of the web root (so it is not directly web accessible) and load it with <cfinclude> tag into the OnApplicationStart() method of each sub-application's App.cfc.  That .CFM file can be as simple as:
    <cfset application.myCustomSetting = "blahblah">
    <cfset application.myOtherSetting = "foo">
    Alternatively, you can look at using a config file like this Ray Camden blog post suggests, and use the GetProfileSection(), GetProfileString(), and SetProfileString() functions as needed within OnApplicationStart().  You could even put ALL of your settings in
    A third option is to store your settings in an XML file or in JSON format in a text file.  You could then write code to read in the XML file, and use something like xml2struct.cfc to convert the XML into a struct, then append the struct to your application scope.  If you go the JSON route, then just read in the JSON file and use DeserializeJSON() to convert it into a struct, and append it to the application scope.
    What I think is probably the best approach is to use a community-supported MVC framework like FW/1 or ColdBox (maybe you already are, I don't think you've said so though).  One of the many advantages to doing so is that they have built-in "environment" support that can be used to configure common settings, depending on your environment (dev/qa/production).  You would handle reading in your external settings through the "environment" mechanism.
    One other thing to think about: your login mechanism.  I think you want to use one set of login tools that is shared by all of the "sub-applications".  You can do this also by putting the login/authentication-related code somewhere outside the webroot of your applications, and then either set up a mapping to that location in CF Admin, or set an application-specific mapping in your various App.cfc files.  That way all the "sub-applications" share a common set of code for the login process.  I don't know how your login process works (do all users go to the same login page then get redirected into their relevant "sub-application", or does each "sub-application" have a discrete login page that utilizes common back-end processes to authenticate and redirect), so you'll have to judge how that is best accomplished.
    Hopefully this gives you some useful ideas.
    -Carl V.

  • Which to use application.cfm or application.cfc?

    Hi,
    Just a general question, i have been using application.cfm
    for my applications so far. I came across a tag that would be used
    under application.cfc, but i tried putting both templates together
    in one application and boom, an error showed up.
    So, which is better to use with most of the applications
    application.cfm or .cfc?
    Thanks for any help!
    Syed

    It's actually a bit easier to use session and application
    scope variables with Application.cfc, I think.
    Application.cfc has methods for specific "events" or states:
    onApplicationStart() -- where to load application variables,
    security logic, etc.
    onSessionStart() -- initialize session varialbes, etc.
    onRequestStart() -- runs at the start of each page request
    onRequestEnd()
    onSessionEnd()
    onApplicationEnd()
    onError() -- very nice place to get some good
    Application-wide error handling code in place
    onRequest() -- be sure to read the notes on this
    method...it's a bit different.
    Check out the MX7 reference page for Application.cfc:
    http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?cont ext=ColdFusion_Documentation&file=00000692.htm
    CF* (if you're using that yet)
    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Part_3_CFML_Ref_1.html

  • SetEncoding() and application.cfc

    Is this a bug, or I just didn't understand the way it is
    supposed to work?
    I just finished determining that if one puts a <cfset
    setEncoding("form","encodingType")> in the
    psudo-consructor (after the
    <cfcomponent...> but before any <cffunction...)
    tags) of Application.cfc
    one will always receive empty form structures on an action
    page.
    When I tried moving said setEncoding() line to the
    onRequestStart()
    function. All was well? Is there a reason for this I do not
    understand
    with my very limited knowledge of page encoding?

    Application.cfc is event-driven, all its methods being
    events. I think
    you should expect to be in uncharted territory if you use any
    method
    different from the given list
    First, you can augment the functions of Applicaiton.cfc if
    you so
    desire, it is just that these functions will never be called
    by any
    event. But there is nothing wrong with them being called by
    functions
    called as a result of one of the defined events.
    Secondly, I was not doing this.
    Relevant parts of my Application.cfc file:
    <cfcomponent output="no">
    <cfprocessingdirective pageencoding="windows-1252" />
    <cfset variables.coding = "windows-1252">
    <!--- placing these setEncoding() functions here, in the
    psudo
    constructor, failed. This cause the form structure to always
    be empty. --->
    <cfset setEncoding("form",variables.coding)>
    <cfset setEncoding("url",variables.coding)>
    <cffunction name="onRequestStart" output="false">
    <cfargument name="requestname" required="yes">
    <!--- placing these setEncoding() functions here, in the
    onRequestStart, works fine. --->
    <cfset setEncoding("form",variables.coding)>
    <cfset setEncoding("url",variables.coding)>
    </cffunction>
    </cfcomponent>

  • Lost on application.cfc

    Hi all,
    I've used application.cfm for ages on our site (now in sustainment) and we have been moved to a new server using CF9. Our server dudes have "per application" settings in place where I can map my custom tag directory (works fine) but when I use application.cfc, I begin crashing on all my pages that use relative pathing.
    For example, the first thing the application does is query an Oracle table to get security settings. This is located off the root in a folder (oddly enough) called Security. That folder has a subdirectory called queries. I bomb with an error saying that "<cfinclude template="queries/user_role_select.cfm">" is invalid and it cannot find the noted cfm file and that I have to set up mappings in my application.cfc file.
    Does this mean that I have to provide mappings for every directory and subdirectory under my root folder? Surely not! If so, how can this be done and how would I use that mapping in my cfincludes? I'm really getting started with the cfc files late in the game so any guidance and direction is GREATLY appreciated.
    Thanks in advance!

    For example, the first thing the application does is query an Oracle table to get security settings. This is located off the root in a folder (oddly enough) called Security. That folder has a subdirectory called queries. I bomb with an error saying that "<cfinclude template="queries/user_role_select.cfm">" is invalid and it cannot find the noted cfm file and that I have to set up mappings in my application.cfc file.
    What is the EXACT error message?  Don't paraphrase it, copy and paste it from the screen.
    Also: what is the full file system path to the file with the <cfinclude> in it, and the file system path to queries/user_role_select.cfm?
    What mappings have you set in CFAdmin and in your Application.cfc pseudo constructor?  Ditto custom tag paths (although the latter ought not be relevant here)?
    Adam

  • Application.cfc and invoking by url a cfc

    hi all!
    i have to invoke by url a cfc. like this...
    http://domain/cfcByUrl.cfc?method=get
    now, if i add application.cfc to root of my application, my
    cfc invoked by url not works! it return only a white page!
    what happen? where do i wrong?
    cfmx7.0.2 on linux
    thanks
    Rob

    vkr, thanks for your reply
    quote:
    You have to call the CFC's through the URL by passing the
    function and its arguments
    yes, it is.
    quote:
    You have to set your function access type to remote
    yes, it is.
    i make some testing.
    if i remove onRequest method in my application.cfc my cfc
    called by url works perfectly. but, i think, is not a good choice
    remove onRequest... :o) this is mine...
    <cffunction name="onRequest" output="Yes">
    <cfargument name="targetPage" type="string"
    required="yes" />
    <cfinclude template="#arguments.targetPage#" />
    </cffunction>
    i test this situation on linux and windows. i've the same
    problem.
    thank
    Rob

  • CFGrid and Application.cfc - bug??

    I don't understand what is happening here.
    If I open the cfgrid.cfm page without the Application.cfc
    file it works fine.
    With the application.cfc file the grid does not populate.
    If I comment out the cfajaximport, onrequeststart, onrequest
    and onrequestend it works fine.

    the best i could find was comment #8 by Scott Jibben here:
    http://www.forta.com/blog/index.cfm/2007/6/4/ColdFusion-Ajax-Tutorial-4-Partial-Page-Updat es
    i was apparently remembering things wrong and it is
    onRequestEnd method
    that seems to be the culprit... though i suppose depending on
    what you
    have in onRequest method may make it a collaborator too... i
    know for
    sure onRequest interferes with flash remoting and invoking
    cfc's as
    webservice...
    but why do you have <cfajaximport ...> tag in your
    Application.cfc???
    iirc, that is not a good practice - you should use it on your
    .cfm page
    in general, and in your particular case i don't think you
    need it at all.
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com

  • Application.cfc site variables

    I switched over to using application.cfc not too long ago. One thing I have struggled with is how to set variables that I use on individual pages of my site like I used to do in application.cfm. I have some passowrds for sftp services etc that I used to set in application.cfm. I have not been able to figure out how to make them work with application.cfc so I can call them where I need to.
    I have tried setting them in onrequeststart, onapplicationstart etc. but nothing seems to work. The variables are never defined.
    Does anyone have a working example of how to set variables that can be used on your site globally?
    Is there a better way to store account passwords and variables like that that I am missing?

    For security reasons, I would try to avoid embedding the password anywhere in your ColdFusion code.  You might put it in a "config" file outside of the webroot, then use ColdFusion to read it into an appropriately scoped variable.  Assuming you don't <cfdump> or WriteDump() your variable scopes anywhere in your production code, and that you don't have "Enable Request Debugging Output" enabled on your production server, you could store the password in either the Application scope or a local page's variables scope.  If there is only one page that will do FTP communication, then loading the password into a variable on that page would be fine.  If you modularize the FTP stuff so it can be reused elsewhere in your application, then put the password in a variable in the application scope.
    Since you'll need to pass an the password to the FTP connection, you can't hash it for added security, which is the best way to handle passwords.  But you can encrypt/de-encrypt it using various functions within ColdFusion.  I'd consider at least storing it in an encrypted form in the "config" file.  While being no where near perfect security, it is better than storing the password in plain text in a file.
    -Carl V.

Maybe you are looking for

  • SOAP Receiver Adapter problem (client certificate required)

    My Scenario is similar to described in https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/3721. [original link is broken] [original link is broken] [original link is broken] I have two PI servers running on one machine. I am trying to post message

  • I couldn't open swf files

    Flash Player is installed but I couldn't open swf files

  • Same JMS queue in 2 differents processes

    Hi, I have 2 processes which listen on the same JMS queue. the first one consumes a message on the queue. if the message contains some information the second process consumes another message (different format) in the queue. the problem is sometimes t

  • Screen shot of google map.  How do I do it?

    How do I take a screen shot of a google map?

  • Performance improve on procedure

    Dear Team, I had written Follwoing procedure.. but it's taking time around 10 mins to execute... Is there any possible can tune this procedure ?? procedure xyz is culprit                    varchar2(30) := 'xyz ' ;recording created_by value when reco