zoukankan      html  css  js  c++  java
  • 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
            }); 

    这样就可以了。

    出自:http://www.cnblogs.com/shunyao8210/archive/2012/07/02/2572801.html

  • 相关阅读:
    C++11之function模板和bind函数适配器
    C++11之右值引用(三):使用C++11编写string类以及“异常安全”的=运算符
    C++11之右值引用(二):右值引用与移动语义
    C++11之右值引用(一):从左值右值到右值引用
    C++Singleton的DCLP(双重锁)实现以及性能测评
    信息熵
    ip访问网站和localhost访问网站中top使用
    方差与协方差
    js获取file控件的完整路径(上传图片预览)
    对线性回归,logistic回归和一般回归
  • 原文地址:https://www.cnblogs.com/xiangzhong/p/5149980.html
Copyright © 2011-2022 走看看