asp.net uploadify文件已上传到指定目录,但进度条却显示的是上传失败信息HTTP Error

来源:互联网 发布:ping命令是哪个端口 编辑:程序博客网 时间:2024/06/16 04:32

问题:

uploadify 多文件上传时,文件已经成功上传到指定目录下,但是进度条却显示上传失败,提示Http Error 错误

造成原因:项目后台有用户登录,用插件uploadfiy上传文件时,造成Session丢失,使原来已经登录的信息在上传的时候,没有传递到服务器。


解决方法:多文件上传时,将session传递到服务器重新写入。


第一步:在使用uploadify插件时,拿出auth和session作为参数传递到服务器。

var auth = "<%=Request.Cookies[FormsAuthentication.FormsCookieName]==nullstring.Empty:Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";

        var ASPSESSID = "<%=Session.SessionID %>";



第二步:在Global.asax文件的Application_BeginRequest方法重新写入。

        protected void Application_BeginRequest(object sender, EventArgs e)
        {


            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]);
            }


            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]);
            }


        }


        private void UpdateCookie(string cookie_name, string cookie_value)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
            if (cookie == null)
            {
                cookie = new HttpCookie(cookie_name);
            }
            cookie.Value = cookie_value;
            HttpContext.Current.Request.Cookies.Set(cookie);//重新设定请求中的cookie值,将服务器端的session值赋值给它
        }


重新编译一下,OK 。

0 0