我的部门。刚买了CF10,我终于将我现有的网络应用程序从CF8更新为CF10。
我对CF10的第一个问题是使用会话变量。当使用较低版本的CF(CF4到CF8)时,我在设置会话变量并在成功登录后在其他页面中获取或使用这些变量时从未遇到任何问题。使用CF 10似乎设置会话变量并在其他页面中使用它们是主要问题。我不确定我在代码中做错了什么。
首先,我以这种方式在Application.cfc中设置会话:
<cfcomponent displayname="Application" output="true">
<cfset THIS.Name ="MyNewApp"/>
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,20,0) />
<cfset THIS.SessionManagement ="YES"/>
<cfset THIS.SessionTimeout = CreateTimeSpan( 0, 0, 20, 0 ) />
<cfset THIS.SetClientCookies = false />
<cffunction name="OnApplicationStart" access="public" returntype="boolean"
output="false">
<cfset application.Main_DSN = "TESTDB">
<cfreturn true />
</cffunction>
<cffunction name="onApplicationEnd" output="false">
<cfargument name="applicationScope" required="true">
</cffunction>
<cffunction name="OnSessionStart" access="public" returntype="void" output="false"
hint="Fires when user session initializes.">
<cfset session.loggedin = "NO">
<cfset session.username = "">
<cfset session.userrights = "">
<cfset session.usergroup = "">
</cffunction>
</cfcomponent>
登录后,验证用户并将值设置为那些session.variables:
........user validation codes here......................
<cfif mylogin NEQ true>
<cflocation url="/login/login.cfm">
<cfabort
<cfelse>
<cfset session.loggedin="Yes">
<cfset session.username="#Trim(Form.username)#">
<CFSET qUserRights = LoginObj.getUserRights('#Trim(Form.username)#')>
<cfset session.userrights = qUserRights><!--- it's a query --->
<CFSET qUserGroup = LoginObj.getUserGroup('#Trim(Form.username)#')>
<cfloop query="qUserGroup">
<cfset session.usergroup = user_group>
<cfbreak>
</cfloop>
<!--- ******* ?????????????????????????
When I do cfdump in at this level, I can see that all of these session variables have
been assigned to their values.
But these session variables are not accessible from other pages. Other pages still show
these session variable without its value.
So, when I use these cfdumps in the index.cfm it is shown as they're not yet assigned
with any values ********* --->
<cfdump var="#session.loggedin#">
<cfdump var="#session.username#">
<cfdump var="#session.userright#">
<cfdump var="#session.usergroup#">
</cfif>
在index.cfm中,登录前我得到了:
session.loggedin = NO
session.username = ["empty string"]
session.userrights = ["empty string"]
session.usergroup = ["empty string"]
登录成功后:
session.loggedin = NO
session.username = ["empty string"]
session.userrights = ["empty string"]
session.usergroup = ["empty string"]
我做错了吗?此代码适用于CF8。
我需要提一下:CF10在Linux中,我的网络应用程序在https而不是http。但是这些会话变量应该在http和https之间共享,因为一些较旧的页面仍在http中,无法移动到https。
答案 0 :(得分:0)
我对这个问题没有直接的答案。但问题不仅在于CF10。我在CF8中遇到过这种情况。我在application.cfc中创建会话变量,但是在其他页面中无法看到(访问)它们。我相信在你的情况下你可能想要考虑区分大小写的检查,因为你在Linux平台上是基本的,因为如果所有其他方法都失败了。