2013-04-24 7 views
1

내 웹 사이트에서 "jquery.uploadify.js"를 사용하고 있으며이 jquery는 ashx 파일을 사용하여 이미지를 폴더에 업로드합니다. .ashx에서 이미지 이름을 저장하기 위해 Session [ "FileNameNews"]을 사용하고 있으며 코드 시작 부분에 내 Session [ "FileNameNews"]이 비어 있습니다. 그러나 2 개 또는 3 개의 이미지 또는 ... 이미지를 업로드 할 때 내 세션 [ "FileNameNews"]이 비어있을 때마다. 나는 사진을 업로드 할 때마다 내 세션을 비우고 싶지 않고 업로드 된 이미지를 상위 .aspx 페이지의 목록 상자에 표시하려고합니다. 다른 수단으로는 uplaod를 시작할 때 빈 세션이 필요하고 업로드가 끝날 때 이미지 이름을 채워야합니다. 한 번에 여러 이미지를 업로드 할 수 있습니다.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이 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; 
    } 
} 
} 

답변

1

경우에, 당신은 결코 try/catch의 오류 메시지를 참조하십시오. 예외를 "삼키기"쉽습니다. try/catch를 삭제하고 브라우저의 디버그 도구를 사용하여 결과 상태 (또는 오류 메시지)를 검사하십시오.