14 Replies Latest reply on May 2, 2016 6:06 AM by WolfShade

    Keep a value across different application names

    WolfShade Level 4

      Hello, all,

       

      I'm trying to find a way to keep something persistent across different application names without using the server scope (which could be lost upon reboot.)

       

      Here's the situation.  I've got a very large site.  Many sections utilize the root application.cfc, but others have their own application.cfc with a unique name.

       

      /dtr/application.cfc   <!--- app name = "dtr" --->
      /dtr/index.cfm
      
      /erc/index.cfm   <!--- uses root app.cfc --->
      
      /mov/application.cfc   <!--- app name = "mov" --->
      /mov/index.cfm
      
      /suv/index.cfm   <!--- uses root app.cfc --->
      
      /zyx/application.cfc   <!--- app name = "zyx" --->
      /zyx/index.cfm
      
      /root/application.cfc   <!--- app name = "ust" --->
      /root/index.cfm
      

       

      No matter which page is loaded, first, (could be bookmarked, or link sent in a message) I need to check to see if the user has seen a banner alert.  If not, display the alert and set a value for all future references.

       

      I thought of session cookies, but when you get to a section with it's own app.cfc and the name changes, boom.. the previous set session value doesn't exist in this new session.

       

      I thought of standard cookies, but I need the cookie to clear if/when the user closes the browser, so the banner will be viewed the next time the user visits.

       

      I (obviously) don't want this alert loading on every page, every time.  That would be super-annoying. 

       

      Any thoughts or suggestions on how to make this work?

       

      V/r,

       

      ^_^

        • 1. Re: Keep a value across different application names
          EddieLotter Level 3

          Session management is the bane of Web application development. It is very fragile and doesn't always represent the seat warmer on the other end of the connection.

           

          The Web server has no idea when the user closes the tab/window/browser, of which there can be several.

           

          You might have a hope if your users are authenticating. That way you can maintain a datetime value in a user table and only show the banner message after a certain timeout duration.

           

          Good luck.

           

          Cheers

          Eddie

          • 2. Re: Keep a value across different application names
            WolfShade Level 4

            Hi, EddieLotter, thanks for replying.

             

            If there were a way to write a cookie to the HD, but remove it when the browser closes (like a session cookie, but not as volatile), that could work.  It wouldn't be a session cookie, so it wouldn't be limited to just one application (based upon app name).  I've tried adding the domain name to it, but that still didn't fix the "different apps, different names" issue.

             

            The users are authenticating, but the timed idea would quickly draw the ire of either the users (if the time is too short) or the decision/policy makers (if the time is too long.)

             

            There has to be a way for the browser to keep a value across different app names (similar to SSO, but not SSO) that I'm just not seeing.

             

            V/r,

             

            ^_^

            • 3. Re: Keep a value across different application names
              BKBK Adobe Community Professional & MVP

              WolfShade wrote:

               

              If there were a way to write a cookie to the HD, but remove it when the browser closes (like a session cookie, but not as volatile), that could work. It wouldn't be a session cookie, so it wouldn't be limited to just one application (based upon app name).

               

              Then the session cookie is in fact what you need. That is, a cookie for which you define no expires attribute. Here the word "session" refers to the browser session, not to the Coldfusion session.

               

              So, with

               

              cookie.someVar = "someValue";

               

              you'll be on your way.

              • 4. Re: Keep a value across different application names
                WolfShade Level 4

                Hi, BKBK,

                 

                That's what I thought.  However, in practice it isn't working that way.

                 

                Based upon the pseudo structure I used in my original post, if I opened a browser and went to the root/index.cfm, which plants the cookie using <cfcookie domain=".example.com" name="bannerDOD" value="yes" /> (no expiry), then went to mov/index.cfm, I should _NOT_ get the banner, again.  But I do.  I assumed it's because the different app.cfc files each set a different name for the application.

                 

                V/r,

                 

                ^_^

                 

                <rolling eyes>  UPDATE:  Let me qualify that.  In production, it's happening as I described.  In staging, it isn't.  wtf

                No.. it isn't, after all.. I'm tired, and didn't thoroughly test it.  The code that plants the cookie is in the root application.cfc, which is ignored when going into a section that has its own sub application.cfc.  So going directly to mov/index.cfm doesn't even check. 

                • 5. Re: Keep a value across different application names
                  BKBK Adobe Community Professional & MVP

                  WolfShade wrote:

                   

                  Hi, BKBK,

                   

                  That's what I thought. However, in practice it isn't working that way.

                   

                  Based upon the pseudo structure I used in my original post, if I opened a browser and went to the root/index.cfm, which plants the cookie using <cfcookie domain=".example.com" name="bannerDOD" value="yes" /> (no expiry), then went to mov/index.cfm, I should _NOT_ get the banner, again. But I do. I assumed it's because the different app.cfc files each set a different name for the application.

                  Sorry, I can't figure out what you mean. Could you please replace the italicized phrase with one about the cookie instead of the banner.

                  • 6. Re: Keep a value across different application names
                    WolfShade Level 4

                    The script checks for the cookie.  If it exists, the requested page loads.  If it doesn't exist, it redirects to a "banner" alert page, sets the cookie, then clicking a button takes the user to the requested page.

                     

                    That's how it's set up, currently.  But, again, because it's in the root application.cfc under onRequestStart(), any section with its own application.cfc doesn't check the root cfc, so the check isn't triggered.

                     

                    I thought about putting it in the header or footer, but not all sections use the root header and footer, so that's not an option, either.

                     

                    V/r,

                     

                    ^_^

                    • 7. Re: Keep a value across different application names
                      BKBK Adobe Community Professional & MVP

                      That has thrown me even higher into the clouds. I was getting there with:

                       

                      Based upon the pseudo structure I used in my original post, if I opened a browser and went to the root/index.cfm, which plants the cookie using <cfcookie domain=".example.com" name="bannerDOD" value="yes" /> (no expiry), then went to mov/index.cfm,...

                       

                      I am now curious to know what happens about the cookie. In particular, what happens when you close the browser. Also, whether this is what you expect or not.

                      • 8. Re: Keep a value across different application names
                        BKBK Adobe Community Professional & MVP

                        I think I understand your last post now. The different directories, and their respective applications, have no code to check for the existence of the cookie. Except the root Application file.

                         

                        If this is correct, then you can just copy the code for checking the cookie to each application file.

                        • 9. Re: Keep a value across different application names
                          WolfShade Level 4

                          BKBK wrote:

                           

                          If this is correct, then you can just copy the code for checking the cookie to each application file.

                          That's what I was hoping to avoid - there are many sub-apps within the root, and should anything need to be changed, then I'll have to manually update each and every one, separately.

                           

                          Is there some sort of global file that can be added to the root?  One that CF knows to run on each sub-app?  Even if done within CFAdmin?

                           

                          V/r,

                           

                          ^_^

                          • 10. Re: Keep a value across different application names
                            BKBK Adobe Community Professional & MVP

                            The neatest solution I can think of in this situation is where the relevant Application CFCs extend the root application file.

                            • 11. Re: Keep a value across different application names
                              WolfShade Level 4

                              Thanks, BKBK.  I'll look that up.  I know nothing of extending application.cfc, but this might just be the silver bullet I'm looking for.

                               

                              V/r,

                               

                              ^_^

                              • 12. Re: Keep a value across different application names
                                Carl Von Stetten Adobe Community Professional & MVP

                                As an related alternative to what BKBK suggested, you can create a CFC that just has a function that does the cookie checking/logic and extend that in all your various Application.cfc files.  Then reference that function in onRequestStart().  You could even name the function onRequestStart and then do "super.onRequestStart()" or "<cfset super.onRequestStart()>" in each Application.cfc.

                                1 person found this helpful
                                • 13. Re: Keep a value across different application names
                                  BKBK Adobe Community Professional & MVP

                                  Come to think of it, Carl's is the better solution. It has greater abstraction, and less coupling.

                                  • 14. Re: Keep a value across different application names
                                    WolfShade Level 4

                                    Thanks, guys.   I'll look up how to extend a cfc to all my Application.cfc files (many) and reference that from there.

                                     

                                    V/r,

                                     

                                    ^_^