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

本文介绍了解决Uploadify多文件上传时出现Session丢失导致上传失败的问题。通过在上传过程中传递并重新写入Session,确保了已登录状态的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

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 。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值