SWFUpload在FF下的Bug[原创]

在公司里把SWFUpload封装成了控件,然测试时候,IE正常,firefox下有问题.
看了下资料:
swfupload是flash采用socket和服务端进行通信了,所以服务端的session值或cookie值在这时候是捕获不到了。在默认的情况下ie是不存在获取不到seesion或cookie值的,然而对于firefox或chrome在dotnet环境下都是不能获取session和cookie值的。
通过 Global.asax 文件你可以覆盖丢失的Session ID cookie,代码如下(引用官方解决方案):

Explaination: This code checks your POST (form) and GET (querystring) for a Session ID. If it finds one then it overrides the session cookie with the value from your POST/GET. Then later when the session is restored the overridden session is what you get (instead of IE's session or a brand new session which was what the bug was causing to happen).
The same sort of thing is done for the Forms Auth cookie, but I didn't actually go back and look at Forms Auth to see how it works to make sure this would work. And I didn't set the Forms Auth bit so it might not even work.
You just need to include a post_param in your SWFUpload page that passes in the session id. Something like:

var swfu = new SWFUpload({
/* lots of settings */
post_params : {
/* other post params */
"ASPSESSID" : "<%=Session.SessionID %>"
}
/* lots more settings */
});

Note: The overriding of the Forms Authentication cookie has not been tested but I think it should still work. Someone will have to let me know.
P.S. & Security Warning: Don't just copy and paste this code in to your ASP.Net application without knowing what you are doing. It introduces security issues and possibilities of Cross-site Scripting.

 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 ready 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 }
28 try
29 {
30 string auth_param_name = "AUTHID";
31 string auth_cookie_name = FormsAuthentication.FormsCookieName;
32 if (HttpContext.Current.Request.Form[auth_param_name] != null)
33 {
34 UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
35 }
36 else if (HttpContext.Current.Request.QueryString[auth_param_name] != null)
37 {
38 UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
39 }
40 }
41 catch (Exception)
42 {
43 }
44 }
45 void UpdateCookie(string cookie_name, string cookie_value)
46 {
47 HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
48 if (cookie == null)
49 {
50 HttpCookie cookie1 = new HttpCookie(cookie_name, cookie_value);
51 Response.Cookies.Add(cookie1);
52 }
53 else
54 {
55 cookie.Value = cookie_value;
56 HttpContext.Current.Request.Cookies.Set(cookie);
57 }
58 }

另外membership也是同过cookie的,在FF中上传也会丢失,导致没有权限不能上传

解决办法:

MEMBER_ASPROLES 是自己随意命名的一个名称,
.ASPROLES 是对应配置文件roleManager节点cookieName的名称

1
try
2 {
3 string membership_param_name = "MEMBER_ASPROLES";
4 string membership_cookie_name = ".ASPROLES";
5
6 if (HttpContext.Current.Request.Form[membership_param_name] != null)
7 {
8 UpdateCookie(membership_cookie_name, HttpContext.Current.Request.Form[membership_param_name]);
9 }
10 else if (HttpContext.Current.Request.QueryString[membership_param_name] != null)
11 {
12 UpdateCookie(membership_cookie_name, HttpContext.Current.Request.QueryString[membership_param_name]);
13 }
14
15 }
16 catch (Exception)
17 {
18 }
原文地址:https://www.cnblogs.com/405464904/p/2163624.html