做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

解決uploadify使用時session發生丟失問題的方法

來源:懂視網 責編:小采 時間:2020-11-27 22:37:25
文檔

解決uploadify使用時session發生丟失問題的方法

解決uploadify使用時session發生丟失問題的方法:今天在使用uploadify時發現session會發生丟失的情況,經過一番研究發現,其丟失并不是真正的丟失,而是在使用Flash上傳控件的時候使用的session機制和asp.net中的不相同。為解決這個問題使用兩種方案,下面進行介紹 第一種:修改Gobal 前臺aspx頁面
推薦度:
導讀解決uploadify使用時session發生丟失問題的方法:今天在使用uploadify時發現session會發生丟失的情況,經過一番研究發現,其丟失并不是真正的丟失,而是在使用Flash上傳控件的時候使用的session機制和asp.net中的不相同。為解決這個問題使用兩種方案,下面進行介紹 第一種:修改Gobal 前臺aspx頁面

今天在使用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'); 
 } 
 }); 
 }); 

接著修改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); 
 } 

在JS加載前面定義下面兩個變量

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

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

這段代碼的功能是將多文件的信息存到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("提示","已存在該文件"); 
 } 
 
 } 
 }); 
 <%-- jQuery裝載函數結束--%> 

動態的傳遞參數,并判斷是否合法

//動態加載 
 function loadFileType(){ 
 //檢測 
 var medianame=Ext.getCmp("eName").getValue(); 
 if(medianame.trim()==""){ 
 Ext.Msg.alert("提示","媒體名稱不能為空"); 
 return; 
 } 
 var filetype=Ext.getCmp("eType").getValue(); 
 if(filetype=="" || filetype<0){ 
 Ext.Msg.alert("提示","請選擇媒體類型"); 
 return; 
 } 
 //動態更新配(執行此處時可獲得值) 
 $("#uploadify").uploadifySettings("scriptData", { "name": medianame,"type":filetype,"sessionuserid":<%=session_userid %> }); 
 //上傳開始 
 $('#uploadify').uploadifyUpload(); 
 } 

<%=session_userid %>是取后臺的一個變量,該變量在加載頁面的時候獲得了session值。當然也可以在前臺直接獲得session值。 
后臺處理程序:

public class FileUploadHelper : IRequiresSessionState, IHttpHandler 
{ 
 
 int nCurrentUserID = -1; 
 public void ProcessRequest(HttpContext context) 
 { 
 try 
 { 
 nCurrentUserID = WebUtil.GetCurrentUserID();//該處的session值得不到 
 } 
 catch (Exception) 
 { 
 } 
 context.Response.ContentType = "text/plain"; 
 context.Response.Charset = "utf-8"; 
 
 string strFilename = string.Empty; 
 int nFiletype = 0; 
 float fFilelength = 0; 
 string strFileExt = string.Empty; 
 string strFilePath = string.Empty; 
 if (context.Request["sessionuserid"] != null) 
 { 
 nCurrentUserID = Convert.ToInt32(context.Request["sessionuserid"].ToString()); 
 } 
 if (context.Request["name"] != null)//獲得文件名(動態參數) 
 { 
 strFilename = context.Request["name"].ToString(); 
 } 
 if (context.Request["type"] != null)//獲得文件類型(動態參數) 
 { 
 nFiletype = Convert.ToInt32(context.Request["type"].ToString()); 
 } 
 if (context.Request["length"] != null)//獲得文件長度(動態參數) 
 { 
 int nEmptFileLength = Convert.ToInt32(context.Request["length"].ToString()); 
 fFilelength = (float)nEmptFileLength / 1024; 
 } 
 if (context.Request["Filename"] != null)//獲得文件名(系統自帶) 
 { 
 string filename = context.Request["Filename"].ToString(); 
 strFileExt = Path.GetExtension(filename).ToLower();//獲得后綴名 
 } 
 HttpPostedFile file = context.Request.Files["Filedata"]; 
 string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]); 
 //根據當前日期創建一個文件夾 
 string dirName = System.DateTime.Now.ToString("yyyyMMdd"); 
 uploadPath += dirName; 
 
 string tmpRootDir = context.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//獲取程序根目錄 
 
 if (file != null) 
 { 
 //判斷目錄是否存在 
 if (!Directory.Exists(uploadPath)) 
 { 
 Directory.CreateDirectory(uploadPath); 
 } 
 //判斷文件是否存在 
 strFilePath = uploadPath + "\\" + strFilename + strFileExt; 
 if (!File.Exists(strFilePath)) 
 { 
 //寫數據庫成功保存文件 
 Media model = new Media(); 
 int newMediaID = -1; 
 model.media_type = nFiletype; 
 model.media_name = strFilename + strFileExt; 
 model.file_path = strFilePath.Replace(tmpRootDir, "");//保存相對目錄 
 model.file_length = fFilelength; 
 newMediaID = MediaBLL.AddMadia(model, nCurrentUserID); 
 if (newMediaID > -1)//數據庫寫入成功 
 { 
 //保存文件 
 file.SaveAs(strFilePath); 
 //下面這句代碼缺少的話,上傳成功后上傳隊列的顯示不會自動消失 
 context.Response.Write("1"); 
 } 
 } 
 else 
 { 
 context.Response.Write("-1"); 
 } 
 } 
 else 
 { 
 context.Response.Write("0"); 
 } 
 } 

這樣就可以解決該問題了。

希望這兩種方法都能幫助大家順利解決session丟失問題,謝謝大家的閱讀。

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

解決uploadify使用時session發生丟失問題的方法

解決uploadify使用時session發生丟失問題的方法:今天在使用uploadify時發現session會發生丟失的情況,經過一番研究發現,其丟失并不是真正的丟失,而是在使用Flash上傳控件的時候使用的session機制和asp.net中的不相同。為解決這個問題使用兩種方案,下面進行介紹 第一種:修改Gobal 前臺aspx頁面
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 馆陶县| 山西省| 夏津县| 蓬莱市| 容城县| 孝昌县| 黔西县| 马边| 潼关县| 饶阳县| 新乐市| 瑞安市| 卢氏县| 正安县| 洛扎县| 和田市| 博湖县| 望都县| 佛坪县| 海晏县| 峨山| 乌拉特中旗| 沾益县| 时尚| 天祝| 晴隆县| 稻城县| 沙坪坝区| 乌鲁木齐县| 霸州市| 大埔区| 湘乡市| 惠安县| 沛县| 怀安县| 故城县| 成都市| 洮南市| 博客| 陵水| 叙永县|