火狐&对象转移到了这里

时间:2010-09-10 00:52:05

标签: asp.net flash firefox

我们有一个asp.net网站,它使用flash电影来上传HTTP文件,它可以在IE上无缝运行。使用firefox时,无法上传.. HTTP调试显示我们发布的页面返回以下内容:

HTTP 302

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fproject_name3%2fDefault.aspx%3fReturnUrl%3d%252fproject_name3%252ffiles%252fuploader.aspx">here</a>.</h2>
</body></html>

这一直困扰着我们一段时间,并感谢任何帮助:)

1 个答案:

答案 0 :(得分:1)

可能是Flash cookie错误:Flash总是发送IE cookie而不管浏览器。例如,当您使用表单身份验证时,这是一个问题:

  1. 创建会话cookie的用户登录。
  2. 用户访问Flash组件(例如上传组件),该组件向服务器发出请求,请求访问会话或受到表单身份验证的影响。
  3. 调用2将失败,因为没有会话cookie发送到服务器,因为会话cookie在Firefox的cookie中,而Flash正在发送IE:s cookies。在您的情况下,似乎用户被重定向到登录页面(似乎是/default.aspx)。

    解决此问题的方法是让Flash组件将cookie作为post参数发送,然后从post参数中重新创建HttpHandler中的cookie。如果需要,我可以发布一些示例代码。

    这是我经常使用的SwfUpload组件的常见问题。我也在umbrao里面使用它,所以我也重新创建了umbraco的登录cookie。

    更新:这是我使用的HttpModule的源代码:

    using System;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Web;
    using System.Web.Configuration;
    using System.Web.Security;
    
    namespace cimkey.utility
    {
    public class SwfUploadModule : IHttpModule
    {
        private NameValueCollection paramNameToCookieName;
    
        private void BuildParamNameToCookieNameList()
        {
            if (paramNameToCookieName != null)
                return;
    
            // ASP.NET session.
            const string session_param_name = "ASPSESSID";
            SessionStateSection SessionSettings = (SessionStateSection)ConfigurationManager.GetSection("system.web/sessionState");
            string session_cookie_name = SessionSettings.CookieName; // "ASP.NET_SESSIONID";
    
            // Forms authentication.
            const string auth_param_name = "AUTHID";
            string auth_cookie_name = FormsAuthentication.FormsCookieName;
    
            paramNameToCookieName = new NameValueCollection
            {
                {   session_param_name,     session_cookie_name }, 
                {   auth_param_name,        auth_cookie_name }, 
                {   "umbracoMemberLogin",   "umbracoMemberLogin"}, 
                {   "umbracoMemberId",      "umbracoMemberId"   }, 
                {   "umbracoMemberGuid",    "umbracoMemberGuid" }
            };
        }
    
        public void Init(HttpApplication context)
        {
            BuildParamNameToCookieNameList();
    
            context.BeginRequest += context_BeginRequest;
        }
    
        public void Dispose()
        {
        }
    
        void context_BeginRequest(object sender, EventArgs e)
        {
            /* 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
            */
    
            try
            {
                foreach (string paramName in paramNameToCookieName.Keys)
                {
                    string cookieName = paramNameToCookieName[paramName];
    
                    if (HttpContext.Current.Request.Form[paramName] != null)
                    {
                        UpdateCookie(cookieName, HttpContext.Current.Request.Form[paramName]);
                    }
                    else if (HttpContext.Current.Request.QueryString[paramName] != null)
                    {
                        UpdateCookie(cookieName, HttpContext.Current.Request.QueryString[paramName]);
                    }
                }
    
            }
            catch (Exception)
            {
            }
        }
    
        static void UpdateCookie(string cookie_name, string cookie_value)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
            if (cookie != null)
            {
                cookie.Value = cookie_value;
                HttpContext.Current.Request.Cookies.Set(cookie);
            }
            else
            {
                cookie = new HttpCookie(cookie_name, cookie_value);
                HttpContext.Current.Request.Cookies.Add(cookie);
            }
        }
    }
    }
    

    修改它以跟踪您的cookie,它目前检查cookie

    • ASP.NET会话
    • 表格认证
    • Umbraco cookies

    它检查post和request参数。您的客户端代码必须确保将这些参数发送到服务器(我在jQuery ajax POST调用中发送这些参数)。