ASP.Net: Working around Flash Cookie Bug AKA restoring the session | SWFUpload


/ Published in: ASP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Global.asax:
  2. <script RunAt="server" Language="C#">
  3.  
  4. /* Fix for the Flash Player Cookie bug in Non-IE browsers.
  5. * Since Flash Player always sends the IE cookies even in FireFox
  6. * we have to bypass the cookies by sending the values as part of the POST or GET
  7. * and overwrite the cookies with the passed in values.
  8. *
  9. * The theory is that at this point (BeginRequest) the cookies have not been ready by
  10. * the Session and Authentication logic and if we update the cookies here we'll get our
  11. * Session and Authentication restored correctly
  12. */
  13. void Application_BeginRequest(object sender, EventArgs e)
  14. {
  15. try
  16. {
  17. string session_param_name = "ASPSESSID";
  18. string session_cookie_name = "ASP.NET_SESSIONID";
  19. string session_value = Request.Form[session_param_name] ?? Request.QueryString[session_param_name];
  20. if (session_value != null) { UpdateCookie(session_cookie_name, session_value); }
  21. }
  22. catch (Exception) { }
  23.  
  24. try
  25. {
  26. string auth_param_name = "AUTHID";
  27. string auth_cookie_name = FormsAuthentication.FormsCookieName;
  28. string auth_value = Request.Form[auth_param_name] ?? Request.QueryString[auth_param_name];
  29.  
  30. if (auth_value != null) { UpdateCookie(auth_cookie_name, auth_value); }
  31. }
  32. catch (Exception) { }
  33. }
  34. void UpdateCookie(string cookie_name, string cookie_value)
  35. {
  36. HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
  37. if (cookie == null)
  38. {
  39. HttpCookie cookie1 = new HttpCookie(cookie_name, cookie_value);
  40. Response.Cookies.Add(cookie1);
  41. }
  42. else
  43. {
  44. cookie.Value = cookie_value;
  45. HttpContext.Current.Request.Cookies.Set(cookie);
  46. }
  47. }
  48.  
  49. </script>
  50.  
  51. C# Page_Load:
  52. uploader.URL = Request.Url +
  53. "?ASPSESSID=" + Session.SessionID +
  54. "&AUTHID=" + (Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value);

URL: http://swfupload.org/forum/generaldiscussion/98

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.