您的位置:首页 > 理论基础 > 计算机网络

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

2015-01-22 16:25 639 查看
问题:

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 。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp.net uploadify error
相关文章推荐