码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-01-22 02:34:47      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

解决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

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

标签:

原文地址:http://www.cnblogs.com/xiangzhong/p/5149980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!