开发者

Is ColdFusion Scripted Linearly? Why this error?

I have received this error

Element CUSTOMERID is undefined in CLIENT. 
D:\Inetpub\wwwsitecom\wwwroot\rders.cfm:296

on a page that begins with the following code:

<cfif NOT CreateObject("component","User.User").IsLoggedIn()>
    <script type="text/javascript">
        window.location.href='/index.cfm';
    </script>
    <cfabort>
</cfif>

<cfif NOT IsDefined("client.customerid")>
    <cfparam name="client.customerid" default="0">
    <script type="text/javascript">
    alert("We're sorry.");
    window.location.href="/logout.cfm";
    </script>
    <cfabort>
</cfif>

and on line 296

<cfinvoke component="Account" method="getAccessInfo" returnvariable="getInfo">
  <cfinvokeargument name="customerid" value="#client.CustomerID#">
</cfinvoke>

The IsLoggedIn Function has this piece of code

<cfif NOT StructKeyExists(client,"customer开发者_开发百科id")>
  <cfset strIsLoggedIn = 0>
</cfif>

If ColdFusion processes scripts linearly, how would it have gotten to the undefined client.customerid on line 296 without processing the first parts of the page?

If ColdFusion does not process scripts linearly, how can I prevent this error?


First, I would check that you aren't creating a variable somewhere (perhaps in an implicit scope in a <cfoutput> or <cfloop> tag) that's named client. Since CF is a late-bound language, that can change the semantics, and references to client.CustomerID will be looking in your local client variable, not the Client scope.

Secondly, if you want to do a redirect, please, please, use <cflocation> instead of doing this crazy JavaScript redirect. Remember that JavaScript is executed on the client side, and it is perfectly possible (and not even that uncommon) for browsers to have JavaScript disabled. <cflocation> results in an HTTP 3xx response being sent, which will work correctly in any browser that implements HTTP, regardless of whether or not JavaScript is enabled. It's also much more secure, since there's no chance of parts of the page being flushed to the client before the redirect.


Make sure you have client variables set up correctly in cfide and check that they are enabled in your Application.cfc file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜