Best way to dynamically set host server in ColdFusion 10 -



Best way to dynamically set host server in ColdFusion 10 -

i utilize next dynamically observe host server. importance making dynamic there many hard coded redirect such as:

http:s//mysite.com/hr/index.cfm

within app. when i'm moving production site development site , production site, have manually change/comment out http/https 1 1 , not time consuming dangerous.

here code found can observe host server. following:

<cfset inet = createobject("java", "java.net.inetaddress")> <cfset inet = inet.getlocalhost()> <cfset hostserver = "#inet.gethostname()#"> <cfset thishostserver = "#left(hostserver,6)#"> <cfswitch expression="#trim(thishostserver)#"><!--- prod or dev server ---> <cfcase value="myprodsite.com"> <cfset usethisurl = "http://myprodsite.com"> </cfcase> <cfcase value="mydevsite.com"> <cfset usethisurl = "http://mydevsite.com"> </cfcase> </cfswitch>

then on each page links or redirection exist, need use:

#usethisurl#/hr/index.cfm

my question is:

where best way set #usethisurl# in application? i'm using coldfusion 10 , application.cfc in linux env.

should set application or session scope?

since in application or session scope, when users idle on page , application/session scope expired, when user click on link generate error? how prevent users seeing error caused using technique? please advice, give thanks you!

best practice used creating config.cfc can contain function getserverspecificvariables() homecoming structure. construction saved in application scope since don't want create usethisurl every session start. when need reset clear application scope. instantiate below config component within onapplicationstart event in application.cfc example

config.cfc:

component{ public struct function getserverspeceficvariables(){ var config = {}; var inet = createobject("java", "java.net.inetaddress"); inet = inet.getlocalhost(); hostserver = inet.gethostname(); thishostserver = left(hostserver,6); switch(trim(thishostserver)){ case 'myprodsite.com':{ config.usethisurl = ''; break; } case 'mydevsite.com':{ config.usethisurl = ''; break; } } homecoming config; } }

coldfusion coldfusion-10

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -