- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章解决uploadify使用时session发生丢失问题的方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
今天在使用uploadify时发现session会发生丢失的情况,经过一番研究发现,其丢失并不是真正的丢失,而是在使用Flash上传控件的时候使用的session机制和asp.net中的不相同。为解决这个问题使用两种方案,下面进行介绍 。
第一种:修改Gobal 前台aspx页面:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
$(
"#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中的代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
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加载前面定义下面两个变量 。
1
2
|
var
auth =
"<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>"
;
var
ASPSESSID =
"<%= Session.SessionID %>"
;
|
Handler文件代码如下: 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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值 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
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装载函数结束--%>
|
动态的传递参数,并判断是否合法 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
//动态加载
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值。 后台处理程序:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
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丢失问题,谢谢大家的阅读.
最后此篇关于解决uploadify使用时session发生丢失问题的方法的文章就讲到这里了,如果你想了解更多关于解决uploadify使用时session发生丢失问题的方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
如果服务器在使用Uploadify上传文件时返回错误(HTTP响应代码!= 200),则上传的文件将显示红色背景,并显示如下消息: file.jpg (52.78KB) - HTTP Error 表示
本文实例为大家分享了java文件上传和预览实现代码,供大家参考,具体内容如下 1、下载uploadify插件 2、index.html ?
我刚刚实现了 uploadify在我的项目中,我注意到上传过程中似乎有一个重要的安全问题: 上传文件的文件夹作为 javascript 参数提供,因此在客户端。如果用户更改脚本,并为上传填写不同的文件
我正在网络上实现uploadify上传照片,并且成功触发响应,Chrome和IE 8上一切正常,但是每次响应警报弹出时Firefox崩溃,无法单击任何内容,我什至无法关闭警报或Firefox,而Fir
我在 uploadify 设置中使用 auto: false ,单击提交按钮时将开始上传,然后一旦触发 onQueueComplete 事件,表单就会提交。但是,当没有选择文件时,onQueueCom
我想使用 uploadify v.3.1 (flash) 上传图像。我单击“选择文件”,选择一个文件,文件已上传,但最终收到错误消息: haus2.jpg (256KB) - HTTP 错误 (401
我正在使用“Uploadify”JQuery 插件进行文件上传。我阅读了文档并引用了示例,并将代码附加到了我的文件中。一切正常,除了上传文件后,文件名消失了。您可以找到文档here . 文档提到了“o
我如何在codeigniter中实现这个? Uploadify(Jquery) 我的意思是 Controller 是什么?进度如何跟踪?如果用户没有安装flashplayer会发生什么? 我如何检查进
是否可以使用 uploadify 实现单个上传进度条和多个文件上传? 最佳答案 Rails 3.1 应用程序的工作解决方案。 它是用于多个上传的单个进度条,但是...我使用了 jQuery.anima
我使用JQuery插件Uploadify用于上传文件。它在所有浏览器中都能正常工作。但是,如果我像这样通过 .htaccess 实现密码保护 AuthType Basic AuthName "Rest
我正在尝试 Uploadify 来清除上传队列并删除上传的文件。问题是这样的。如果我上传 5 个文件(uploadLimit 为 5 组),它们会第一次上传。但是如果我使用这个清除队列: Clear
开幕式 我有几种形式(在本例中是两种),它们位于使用 Ext-JS 的选项卡中。 我还有用于主要 JavaScript 脚本/编程的 jQuery 框架。 last 是一个保存状态的 Javascri
好的,我有一个表单下拉列表 Cheesecakes Fruitcakes 和一个隐藏的文本输入 在我的 jquery/javascript 中 $('#select_category').cha
我正在尝试使用 Uploadify 上传多个文件, $('#fileuploadinput').uploadify({ uploader: '/js/uploadify/uploadify.s
有没有办法在uploadify中限制上传到1个文件? 我在文档中看不到任何内容?我对最大文件大小进行了位排序,但找不到一种方法将其限制为仅允许选择一个文件。 最佳答案 尝试将“multi”设置为 fa
我正在尝试实现 uploadify,以下是我的设置 $('#file_upload').uploadify({ 'uploader' : 'uploadify/uploadify.s
我正在寻找在 jQuery 插件中拥有不同文件类型的解决方案 Uploadify . 考虑以下过程:您想要使用您选择的程序打开一个文件。从默认的操作系统对话框开始,您可以在下拉菜单中选择不同的文件类型
我有一个 Send.aspx 页面,上面有一个 uploadify 控件。 Upload.ashx 处理文件上传。 我正在将文件记录添加到 Upload.ashx 文件中的 sql 数据库,完成后我需
我正在尝试使用 uploadify 将图像上传到远程服务器。对于跨脚本问题或其他问题,我已经做了我能想到的一切。 这是我所做的。 上传功能中的“始终”脚本访问。我的 ww2 服务器上有一个 cross
我只是想为标题添加一个简单的文本字段并将其发布到 uploadify.php,但它不起作用。 Javascript: $(function() { $("#file_upload").uplo
我是一名优秀的程序员,十分优秀!