0
我有一個會話問題,其中我的處理程序未讀取會話值。這隻發生在我們的服務器上。當我運行本地時,它工作正常。我也在調用IRequiresSessionState,所以這也不應該成爲問題。會話狀態在服務器上的ashx文件中不起作用
我能夠看到會話狀態仍在工作,直到我打電話給我的ashx文件。但是,在這個文件裏,根據我的蹤跡,會話丟失了。
這裏是我的javascript代碼,我用它來打電話給我的處理程序:
$(document).ready(function() {
$("#<%=btnAdd.ClientID%>").uploadify({
'uploader': '../Scripts/Uploadify/uploadify.swf',
'script': '../Handlers/file1.ashx?mode=schedule',
'cancelImg': '../Images/cancel.png',
'wmode': 'transparent',
'hideButton': true,
'fileExt': '*.XML;*.xml;*.CIF;*.cif;*.zip;*.ZIP',
'fileDesc': 'Schedule Files',
'onComplete': function (event, queueID, fileObj, response, data) {
$('#pnlOverlayFrame').show();
document.getElementById("<%=hdnFilePath.ClientID%>").value = response;
},
'onAllComplete': function (event, queueID, fileObj, response, data) {
$get('<%= hdnDirty.ClientID %>').value = '0';
// document.getElementById('<%= btnConfirm.ClientID %>').click();
document.getElementById('<%= btnUploadFiles.ClientID %>').click();
}
,
'multi': true,
'expressInstall': '../Scripts/Uploadify/expressInstall.swf'
});
下面是我的處理程序cs文件代碼
try
{
HttpPostedFile postedFile = context.Request.Files["Filedata"];
if (context.Session != null && context.Session["CurrentDirectory"] != null)
{
StorageRoot = context.Server.MapPath(context.Session["CurrentDirectory"].ToString());
}
else
{
//string DirectoryName = "OP1" + "_" + DateTime.Now.ToString().Replace('/', '_').Replace(':', '_').Replace(' ', '_') + Guid.NewGuid().ToString();
string DirectoryName = "OP1" + "_" + String.Format("{0:yyyyMdHHmmss}", DateTime.Now) + Guid.NewGuid().ToString();
//DirectoryName = DirectoryName.Remove(DirectoryName.Length - 3, 3);
HttpContext.Current.Session.Add("CurrentDirectory", DirectoryName);
//context.Session["CurrentDirectory"] = DirectoryName;
StorageRoot = context.Server.MapPath(DirectoryName);
}
string filename = postedFile.FileName;
if (!Directory.Exists(StorageRoot))
Directory.CreateDirectory(StorageRoot);
postedFile.SaveAs(StorageRoot + @"\" + filename);
context.Response.Write(StorageRoot);
context.Response.StatusCode = 200;
}
catch (Exception ex)
{
context.Response.Write("Error: " + ex.Message);
}
每次它會在其他兼職,並創建新的文件夾按碼。 請指點
可能是使用currentDirectory在服務器沒有設置 –
斐伊川感謝的答案,但currentDirectory所會話名稱 –