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

  • 相关阅读:
    关于如何Debug进MVC3源代码
    浏览文件按钮
    C#多线程学习(五) 多线程的自动管理(定时器)
    记录总数
    Json对象格式化字符串输出
    数据与通信之WebRequest.Web
    ASP.NET MVC3中的ViewBag动态性
    SQL Server 2005的XML数据修改语言(XML DML)
    SOCKET与TCP/IP与HTTP的关系
    WPF绑定方式
  • 原文地址:https://www.cnblogs.com/xiangzhong/p/5149980.html
Copyright © 2011-2022 走看看