因為在火狐瀏覽器下Flash發送的請求不會帶有cookie,所以導致后台的session失效。
解決的方法就是手動傳遞SessionID到后台。
$("#fileresultfiles").uploadify({
swf: '/Scripts/uploadify/uploadify.swf',
uploader: '/UploadFiles.ashx',
queueID: 'fileQueue',
buttonText: '附件上傳',
auto: true,
debug: false,
removeCompleted: true,
multi: true,
displayData: 'speed',
uploadLimit: 20,
fileSizeLimit: '500MB',
formData: {
'ASPSESSID': '<%=Session.SessionID %>',
'primarykey': $("#<%=hid_resultStrId.ClientID %>").val(),
},
onQueueComplete: function (queueData) {
//隊列上傳完成后,ajax獲取上傳的所有列表
AjaxRequestFile();
},
onSelectError: function (file, errorCode, errorMsg) {
var errorMsg = "";
if (errorCode == "QUEUE_LIMIT_EXCEEDED") {
errorMsg = "文件數量過多!";
}
if (errorCode == "-110") {
errorMsg = "文件大小超出限制!";
}
$('#' + file.id).find('.data').html(' errorMsg');
},
onUploadSuccess: function (file, data, response) {
if (data != "OK") {
$("#fileresultfiles").uploadify('cancel', '*');
alert(data);
}
}
});
'ASPSESSID': '<%=Session.SessionID %>'這句就是把SessionID傳遞過去
然后在Global.asax文件中監聽每一個請求,如果有SessionID傳過來就重新設置cookie
protected void Application_BeginRequest(object sender, EventArgs e)
{
//為了Uploadify在谷歌和火狐下不能上傳的BUG
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
{
}
}
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);//重新設定請求中的cookie值,將服務器端的session值賦值給它
}
}
