• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ASP.NET > 解决uploadify使用时session发生丢失问题的方法

解决uploadify使用时session发生丢失问题的方法

作者:萤火虫小Q 字体:[增加 减小] 来源:互联网 时间:2017-05-11

萤火虫小Q通过本文主要向大家介绍了uploadify session,uploadify,uploadify官网,uploadify参数,uploadify api等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

今天在使用uploadify时发现session会发生丢失的情况,经过一番研究发现,其丢失并不是真正的丢失,而是在使用Flash上传控件的时候使用的session机制和asp.net中的不相同。为解决这个问题使用两种方案,下面进行介绍

第一种:修改Gobal
前台aspx页面:

$("#uploadify").uploadify({ 
        'uploader': '/LZKS/Handler/BigFileUpLoadHandler.ashx', 
        'swf': '/LZKS/Scripts/uploadify/uploadify.swf', 
        'cancelImage': '/LZKS/Scripts/uploadify/cancel.png', 
        'queueID': 'fileQueue', 
        //'auto': false, 
        'multi': true, 
        'buttonText': '文件上传', 
        'formData': { 'ASPSESSID': ASPSESSID, 'AUTHID': auth }, 
        'onSelect': function (file) { 
          $('#uploadify').uploadifySettings('formData', { 'ASPSESSID': ASPSESSID, 'AUTHID': auth }); 
          alert(formDate); 
        }, 
        'onComplete': function (file, data, response) { 
        }, 
 
        'onQueueComplete': function () { 
          alert("上传完成!"); 
          $('#fileQueue').attr('style', 'visibility :hidden'); 
        }, 
        'onSelectError': function (file, errorCode, errorMsg) { 
          $('#fileQueue').attr('style', 'visibility :hidden'); 
        }, 
        'onUploadStart': function (file) { 
          $('#fileQueue').attr('style', 'top:200px;left:400px;width:400px;height :400px;visibility :visible'); 
        } 
      }); 
    }); 
</div>

接着修改Gobal中的代码:

protected void Application_BeginRequest(object sender, EventArgs e) 
    { 
      /* we guess at this point session is not already retrieved by application so we recreate cookie with the session id... */ 
      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); 
    } 
</div>

在JS加载前面定义下面两个变量

var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>"; 
 var ASPSESSID = "<%= Session.SessionID %>"; 
</div>

Handler文件代码如下:  

 public class BigFileUpLoadHandler : IHttpHandler, IRequiresSessionState 
  { 
    DALFile Fdal = new DALFile(); 
    public void ProcessRequest(HttpContext context) 
    { 
      context.Response.ContentType = "text/plain"; 
      VideoUpLoad(context, CLSOFT.Web.LZKS.Edu.Globe.filename); 
    } 
    public void VideoUpLoad(HttpContext context, string fileFolderName) 
    { 
      context.Response.Charset = "utf-8"; 
      string aaaaaaa=context.Request.QueryString["sessionid"]; 
      HttpPostedFile file = context.Request.Files["Filedata"]; 
      string uploadPath = HttpContext.Current.Server.MapPath(UploadFileCommon.CreateDir(fileFolderName)); 
      if (file != null) 
      { 
        if (!Directory.Exists(uploadPath)) 
        { 
          Directory.CreateDirectory(uploadPath); 
        } 
        Model.ModelFile model = new Model.ModelFile(); 
        model.File_ID = Guid.NewGuid().ToString(); 
        model.File_Name = file.FileName; 
        model.File_Path = UploadFileCommon.CreateDir(fileFolderName); 
        model.File_Size = file.ContentLength; 
        model.File_Extension = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1); 
        model.File_Date = DateTime.Now; 
        model.File_CurrentMan = CLSOFT.Web.LZKS.Edu.Globe.name; 
        file.SaveAs(uploadPath + model.File_Name); 
       
        List<Model.ModelFile> list = null; 
        if (context.Session["File"] == null) 
        { 
          list = new List<Model.ModelFile>(); 
        } 
        else 
        { 
          list = context.Session["File"] as List<Model.ModelFile>; 
        } 
        list.Add(model); 
        context.Session.Add("File", list); 
      } 
      else 
      { 
        context.Response.Write("0"); 
      }  
    } 
</div>

这段代码的功能是将多文件的信息存到context.Session["File"] as List<Model.ModelFileModel.ModelFile>为文件信息类 实现批量上传的信息给Session 
第二种方案:直接向后台传递session值

Ext.onReady(function () { 
    Ext.QuickTips.init(); 
    <%--JQuery装载函数--%> 
      $("#uploadify").uploadify({ 
        'uploader': '../Uploadify-v2.1.4/uploadify.swf',//上传swf相对路径 
        'script': '../Service/FileUploadHelper.ashx',//后台上传处理呈现 
        'cancelImg': '../Uploadify-v2.1.4/cancel.png',//取消上传按钮相对路径 
        'checkExisting':true,//服务端重复文件检测 
        'folder': '../UploadFile/',//上传目录 
        'fileExt':'*.jpg;*.png;*.gif;*.bmp',//允许上传的文件格式 
        'fileDesc':'jpg、png、gif、bmp',//文件选择时显示的提示 
        'queueID': 'fileQueue',//上传容器 
        'auto': false, 
        'multi': false,//只允许单文件上传 
        'buttonText':'Choose File', 
        'scriptData': { 'name': '', 'type': '','length':'' },//在加载时此处是null 
        //'onInit':function(){alert("1");},//初始化工作,在Extjs的嵌套中最先触发的函数 
        //选择一个文件后触发 
        'onSelect': function(event, queueID, fileObj) { 
//          alert("唯一标识:" + queueID + "\r\n" + 
//          "文件名:" + fileObj.name + "\r\n" + 
//          "文件大小:" + fileObj.size + "\r\n" + 
//          "创建时间:" + fileObj.creationDate + "\r\n" + 
//          "最后修改时间:" + fileObj.modificationDate + "\r\n" + 
//          "文件类型:" + fileObj.type); 
           $("#uploadify").uploadifySettings("scriptData", { "length": fileObj.size}); //动态更新配(执行此处时可获得值) 
        }, 
        //上传单个文件接收后触发 
        'onComplete': function (event, queueID, fileObj, response, data) { 
           var value = response; 
           if(value==1){ 
           Ext.Msg.alert("提示","上传成功"); 
           } 
           else if(value==0){ 
           Ext.Msg.alert("提示","请选择上传文件"); 
           } 
           else if(value==-1){ 
            Ext.Msg.alert("提示","已存在该文件"); 
           } 
    



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 解决uploadify使用时session发生丢失问题的方法

相关文章

  • 2017-05-11ASP.Net防止刷新自动触发事件的解决方案
  • 2017-05-11xml 文件的创建和读取代码
  • 2017-05-11利用ASP.NET MVC和Bootstrap快速搭建个人博客之后台dataTable数据列表
  • 2017-05-11LINQ字符串向datetime 转换时失败的处理方法
  • 2017-05-11ASP.NET Get和Post两种提交方法浅析
  • 2017-05-11IIS7 应用程序池的 托管管道模式与集成模式小结
  • 2017-05-11ASP.NET实现个人信息注册页面并跳转显示
  • 2017-05-11ASP.NET 窗体间传值的方法
  • 2017-05-11asp.net实现微信公众账号接口开发教程
  • 2017-05-11asp.net服务器上几种常见异常的解决方案.

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • ASP.NET(C#) 读取EXCEL另加解决日期问题的方法分享
    • .net开发中几个重要的认识误区小结
    • asp.net微信开发(高级群发图文)
    • URL中去除指定参数实现C#代码
    • ASP.net(c#)用类的思想实现插入数据到ACCESS例子
    • .NET简单工厂模式讲解
    • .NET Core控制台应用程序如何使用异步(Async)Main方法详解
    • ASPX向ASCX传值以及文本创建图片(附源码)
    • .NET微信公众号获取OpenID和用户信息
    • 为T-SQL添加intellisense功能

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有