Return to Snippet

Revision: 14127
at May 19, 2009 17:42 by jink


Initial Code
Global.asax:
<script RunAt="server" Language="C#">

	/* Fix for the Flash Player Cookie bug in Non-IE browsers.
* Since Flash Player always sends the IE cookies even in FireFox
* we have to bypass the cookies by sending the values as part of the POST or GET
* and overwrite the cookies with the passed in values.
*
* The theory is that at this point (BeginRequest) the cookies have not been ready by
* the Session and Authentication logic and if we update the cookies here we'll get our
* Session and Authentication restored correctly
*/
    void Application_BeginRequest(object sender, EventArgs e)
    {
		try
		{
			string session_param_name = "ASPSESSID";
			string session_cookie_name = "ASP.NET_SESSIONID";
			string session_value = Request.Form[session_param_name] ?? Request.QueryString[session_param_name];
			if (session_value != null) { UpdateCookie(session_cookie_name, session_value); }
		}
		catch (Exception) { }

		try
		{
			string auth_param_name = "AUTHID";
			string auth_cookie_name = FormsAuthentication.FormsCookieName;
			string auth_value = Request.Form[auth_param_name] ?? Request.QueryString[auth_param_name];

			if (auth_value != null) { UpdateCookie(auth_cookie_name, auth_value); }
		}
		catch (Exception) { }
    }
	void UpdateCookie(string cookie_name, string cookie_value)
	{
		HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
		if (cookie == null)
		{
			HttpCookie cookie1 = new HttpCookie(cookie_name, cookie_value);
			Response.Cookies.Add(cookie1);
		}
		else
		{
			cookie.Value = cookie_value;
			HttpContext.Current.Request.Cookies.Set(cookie);
		}
	}
       
</script>

C# Page_Load:
uploader.URL = Request.Url +
				"?ASPSESSID=" + Session.SessionID +
				"&AUTHID=" + (Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value);

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

Initial Description

                                

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

Initial Tags
flash, aspnet

Initial Language
ASP