【问题标题】:ColdFusion session variables are not accessible in other pagesColdFusion 会话变量在其他页面中不可访问
【发布时间】:2014-06-23 18:00:37
【问题描述】:

我的部门。刚刚购买了 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 中,我的 Web 应用程序在 https 而不是 http。但是这些 session 变量应该在 http 和 https 之间共享,因为一些旧页面还在 http 中,无法移动到 https。

【问题讨论】:

  • 您是否也可以在会话范围内定义timestamp 并将其设置在“Application.cfc”中并在登录后检查每个级别显示的时间戳。
  • 嗨!我不太听从你的指示
  • onSessionStart() 添加类似 &lt;cfset session.started = now()&gt; 的内容。
  • 我需要等到这个晚上才停止并重新启动服务器,因为现在它无法识别什么是 session.started,因为我一直在使用 application.cfc。其他开发人员仍在使用开发服务器,我现在无法停止服务器。我会告诉你。如果您不介意让我知道,您这样做是为了达到什么目的
  • 我在 OnSessionStart 中添加了 。当我打开登录表单时,我执行 并显示: session.started: 02:50:14 session.loggedin: NO session.username: [empty string] session.userrights: [empty string] session.usergroup : [empty string] Session.adv_username: [empty string] Session.pswd: [empty string] 但是登录后,我收到一条错误消息:Element STARTED is undefined in SESSION.

标签: coldfusion coldfusion-10


【解决方案1】:

我对这个问题没有直接的答案。然而,问题不仅在CF10。我在 CF8 中遇到了这种情况。我在 application.cfc 中创建会话变量,但是在其他页面中无法看到(访问)它们。我相信在您的情况下,您可能需要考虑区分大小写的检查,因为您在 Linux 平台上,因为如果一切都失败了,这可能看起来很初级。

【讨论】:

    猜你喜欢
    • 2013-08-16
    • 2019-04-25
    • 2017-09-11
    • 2012-06-17
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    相关资源
    最近更新 更多