1
我在我的網站中使用「jquery.uploadify.js」,這個jQuery使用ashx文件上傳圖片到一個文件夾。在.ashx中,我使用Session [「FileNameNews」]來保存圖像名稱,並且在我的代碼開始處清空我的Session [「FileNameNews」]。但是,當我上傳兩個或三個或...圖像,每次我的會議[「FileNameNews」]是空的。我不想在每次上傳照片時清空我的會話,並且希望上傳的圖像顯示在父.aspx頁面的列表框中。其他手段,我需要在上傳開始時將我的會話清空,並在上傳結束時填入圖像名稱。我可以一次上傳多張圖片。如何在asp.net中設置.ashx文件中會話的值?
有沒有人有想法?請幫幫我。
謝謝。
.aspx頁面中:
<script type = "text/javascript">
$(window).load(
function() {
$("#<%=FileUpload1.ClientID%>").fileUpload({
'uploader': 'scripts/uploader.swf',
'cancelImg': 'images/cancel.png',
'buttonText': 'Browse Files',
'script': 'Upload.ashx',
'folder': 'Temp',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'multi': true,
'auto': false
});
}
);
</script>
<a href="javascript:$('#<%=FileUpload1.ClientID%>').fileUploadStart()">Start Upload</a>
|<a href="javascript:$('#<%=FileUpload1.ClientID%>').fileUploadClearQueue()">Clear</a>
<div style = "padding:40px">
<asp:FileUpload ID="FileUpload1" runat="server" />
</div>
和Upload.ashx:
public class Upload : IHttpHandler, IRequiresSessionState {
public void ProcessRequest(HttpContext context)
{
context.Session["FileNameNews"] = "";
context.Response.ContentType = "text/plain";
context.Response.Expires = -1;
try
{
HttpPostedFile postedFile = context.Request.Files["Filedata"];
string savepath = "";
string tempPath = "";
tempPath = "Temp";//System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
savepath = context.Server.MapPath(tempPath);
string filename = postedFile.FileName;
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
string SitePath = context.Server.MapPath(context.Request.ApplicationPath) + @"\Temp\";
string SitePath1 = context.Server.MapPath(context.Request.ApplicationPath) + @"\WebImages\NewsImages\";
string FileN = SitePath + filename + "{---}" + context.Session["UserID"].ToString();
if ((File.Exists(SitePath + filename + "{---}" + context.Session["UserID"])) || (File.Exists(SitePath1 + filename)))
{
return;
}
else
{
postedFile.SaveAs(savepath + @"\" + filename);
postedFile.SaveAs(savepath + @"\" + filename + "{---}" + context.Session["UserID"]);
if (context.Session["FileNameNews"] == "") { context.Session["FileNameNews"] = filename; }
else { context.Session["FileNameNews"] = context.Session["FileNameNews"] + "," + filename; }
context.Response.Write(tempPath + "/" + filename);
context.Response.StatusCode = 200;
}
}
catch (Exception ex)
{
context.Response.Write("Error: " + ex.Message);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}