ASP.NET MVC 使用Jquery Uploadify 在非IE浏览器下Http Error的解决方案

解决Uploadify上传控件在非IE浏览器中不工作,需要做如下2步修改:

1.Global.asax文件中,实现Application_BeginRequest函数: 

  void Application_BeginRequest( object sender, EventArgs e)
        {
             try
            {
                 string session_param_name =  " ASPSESSID ";
                 string session_cookie_name =  " ASP.NET_SessionId ";
                 if (HttpContext.Current.Request.Form[session_param_name] !=  null)
                {
                    UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
                }
                 else  if (HttpContext.Current.Request.QueryString[session_param_name] !=  null)
                {
                    UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
                }
            }
             catch { }

             try
            {
                 string auth_param_name =  " AUTHID ";
                 string auth_cookie_name = FormsAuthentication.FormsCookieName;
                 if (HttpContext.Current.Request.Form[auth_param_name] !=  null)
                {
                    UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
                }
                 else  if (HttpContext.Current.Request.QueryString[auth_param_name] !=  null)
                {
                    UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
                }
            }
             catch { }
        } 

         private  void UpdateCookie( string cookie_name, string cookie_value)
        {
            HttpCookie cookie =HttpContext.Current.Request.Cookies.Get(cookie_name);
             if( null== cookie)
            {
                cookie = new HttpCookie(cookie_name);
            }
            cookie.Value= cookie_value;
            HttpContext.Current.Request.Cookies.Set(cookie);}

        } 


2. 前台js修改,注意红色代码:

// upload
         var auth = "@(Request.Cookies[FormsAuthentication.FormsCookieName]==null?string.Empty:Request.Cookies[FormsAuthentication.FormsCookieName].Value)";
        var ASPSESSID = "@(Session.SessionID )";

        $( ' #fileInput1 ').uploadify({
             ' uploader '' /Content/uploadify.swf?var= ' +  new Date().getTime(),
             ' script '' /Money/ImportMoneyInDue ',
             ' folder '' /UploadFiles ',
             ' cancelImg '' /Content/cancel.png ',
             'scriptData':  { ASPSESSID: ASPSESSID, AUTHID: auth },
             ' fileExt '' *.xls;*.csv ',
             ' fileDesc '' *.xls;*.csv ',
             ' sizeLimit '1024 *  1024 *  4// 4M
             ' multi 'false,
             ' onComplete ': fun

        }); 

这样就可以了。

 

你可能感兴趣的:(ASP.NET MVC 使用Jquery Uploadify 在非IE浏览器下Http Error的解决方案)