Flash Cookie Bug

搞flash多文件上传搞到几乎吐血,今天解决了最后一个问题
使用了 swfupload
IE下一切正常,Firefox下上传正常,但是保存上传信息到数据库的时候发现uploadhandle保存的Session在其他页面里取不到。
调试发现浏览两个不同页面的SessionID都不同,sh*t
速度超快的google浏览器问题同Firefox...

google到问题原因: http://www.swfupload.org/forum/generaldiscussion/383
I want to clarify what I have observed about the Flash Cookie bug.
The Flash Player Plugin for FireFox, Opera and Safari (and probably other non-IE based browsers) has a bug which sends persistent cookies from IE to the upload URL instead of the cookies from the browser. Session only cookies from IE are not sent.

When Flash initializes in the browser its own empty "cookie space" is created. It loads persistent cookies from IE (which you can see in %USERPROFILE%/cookies). In-memory (session) cookies are not loaded.

The cookies from the browser are not loaded in to Flash's cookie space.

Any session cookies created by the upload script are maintained in-memory in Flash's cookies space. New persistant cookies are created on disk (which you can see in %USERPROFILE%/cookies) and will immediately appear in IE. Cookies created in the Flash cookie space will not appear in any of the browser's "view cookie" tools.

All Flash Movies share the same per browser cookie space which is maintained until the browser is closed (i.e., multiple tabs in FireFox will share the same Flash cookie space but FireFox and Safari maintain separate Flash cookie spaces).

I've carefully tested this issue in FireFox 3 and IE 7 on Windows XP Pro with Flash Player 9.0.115. I also did some basic testing in Opera 9.24 and the Safari Beta for Windows. I plan to create a new demo which will demonstrate my findings.

I have not tested this issue on OS X or in Linux.

同时抄来一份解决办法:

Global.asax:

  1. void Application_BeginRequest(object sender, EventArgs e)
  2.     {
  3.         /* Fix for the Flash Player Cookie bug in Non-IE browsers.
  4.          * Since Flash Player always sends the IE cookies even in FireFox
  5.          * we have to bypass the cookies by sending the values as part of the POST or GET
  6.          * and overwrite the cookies with the passed in values.
  7.          * 
  8.          * The theory is that at this point (BeginRequest) the cookies have not been read by
  9.          * the Session and Authentication logic and if we update the cookies here we'll get our
  10.          * Session and Authentication restored correctly
  11.          */
  12.         try
  13.         {
  14.             string session_param_name = "ASPSESSID";
  15.             string session_cookie_name = "ASP.NET_SESSIONID";
  16.             if (HttpContext.Current.Request.Form[session_param_name] != null)
  17.             {
  18.                 UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
  19.             }
  20.             else if (HttpContext.Current.Request.QueryString[session_param_name] != null)
  21.             {
  22.                 UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
  23.             }
  24.         }
  25.         catch (Exception)
  26.         {
  27.             Response.StatusCode = 500;
  28.             Response.Write("Error Initializing Session");
  29.         }
  30.         try
  31.         {
  32.             string auth_param_name = "AUTHID";
  33.             string auth_cookie_name = FormsAuthentication.FormsCookieName;
  34.             if (HttpContext.Current.Request.Form[auth_param_name] != null)
  35.             {
  36.                 UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
  37.             }
  38.             else if (HttpContext.Current.Request.QueryString[auth_param_name] != null)
  39.             {
  40.                 UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
  41.             }
  42.         }
  43.         catch (Exception)
  44.         {
  45.             Response.StatusCode = 500;
  46.             Response.Write("Error Initializing Forms Authentication");
  47.         }
  48.     }
  49.     void UpdateCookie(string cookie_name, string cookie_value)
  50.     {
  51.         HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
  52.         if (cookie == null)
  53.         {
  54.             cookie = new HttpCookie(cookie_name);
  55.             HttpContext.Current.Request.Cookies.Add(cookie);
  56.         }
  57.         cookie.Value = cookie_value;
  58.         HttpContext.Current.Request.Cookies.Set(cookie);
  59.     }
js:
  1.             swfu = new SWFUpload({
  2.                 // Backend Settings
  3.                 upload_target_url: "uploadhandle.aspx"// Relative to the SWF file
  4.                 post_params : {
  5.                     "ASPSESSID" : "<%=Session.SessionID %>"
  6.                 },
  7. ……
最后,鄙视这个bug
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值