;中国 COLD FUSION 用户组; WWW.CFWINDOW.COM 
您的位置 :首页 >> CF 技巧文章 >> 阅读文章内容 [ 关闭窗口 ]      

技巧文章内容 
    在有<cflocation>存在的页面里面避免使用set cookie.
文章作者 : Linkfoxo [ fengjf@novasprint.com ]          Web URL : http://
上载日期 : 2000-11-21

原因很简单: 就是还没有来得急在用户端设置cookie时已经被跳转到其他页面了.请看下面的文章:

The Situation:

You have written some code that validates a user, then writes a cookie with the userID. Once this is done, you use <cflocation> to take the user to a main menu...but when you do so, you find the cookie was never set.

The Solution:

When is a bug not a bug? Well, in this case, the behavior is unwanted, but not unexpected. But instead of dealving into the inner workings of the HTTP specification, here are two easy ways to get the desired behavior. One uses just a bit of JavaScript and the other is a pure CF solution. (Thanks to Jim Smith who provided me with the CF-only solution.)

Javascript version:



<cfcookie name="userID" value="#validateUser.userID#">



<script language="javascript">

 location.url = "someOtherFile.cfm"

</script>



[Note: the location property, "mainMenu.cfm" is a relative pathname. You can also use absolute pathnames.]

ColdFusion-only version:

<CFCOOKIE NAME="someName" VALUE="someValue">

<CFHEADER NAME="Refresh" VALUE="0; URL=someURL.cfm">







< 联系我们 --- 中国Cold Fusion用户组>

CFUG 国内(总部):Linkfoxo    上海:CFANS    北京:Cafe,Cyberkid,liwater    沈阳:Wangking
  
哈尔滨:Baiming    浙江:梅盛松    江西:陈末
  
CFUG (国际) Nagoya(名古屋):Codeguru    新加坡:YUZI    新西兰(Auckland):Richard CHEN
Copyright 2000-2001 www.cfwindow.com.All rights reserved

;中国 COLD FUSION 用户组; WWW.CFWINDOW.COM