2011-03-04 44 views
0

我使用Uploadify上傳與ASP.NET一些圖像不確定的。
我在ASP.NET中使用Response.WriteFile()將上傳結果返回給JavaScript。 正如文檔中所述,我使用onAllComplete事件來檢查來自ASP.NET的響應字符串。Uploadify響應值總是從ASP.NET

的問題是它的alert(response);在JavaScript中總是不確定的。

JavaScript代碼如下:

$(document).ready(function() { 
      var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>"; 
      $('#btnUpdateProfileImg').uploadify({ 
       'uploader': '../script/uploadify/uploadify.swf', 
       'script': '../uploadprofimg.aspx', 
       'cancelImg': '../script/uploadify/cancel.png', 
       'folder': '../script/uploadify', 
       'scriptData': { 'id': $(this).attr("id"), 'token': auth }, 
       'onAllComplete': function(event, queueID, fileObj, response, data) { 
        alert(response); 
       } 
      }); 
     }); 

ASP.NET代碼低於;

protected void Page_Load(object sender, EventArgs e) 
    { 
     try 
     { 
      string token = Request.Form["token"].ToString(); 
      FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(token); 
      if (ticket != null) 
      { 
       var identity = new FormsIdentity(ticket); 
       if (identity.IsAuthenticated) 
       { 
        HttpPostedFile hpFile = Request.Files["ProfileImage"];  
        string appPath = HttpContext.Current.Request.ApplicationPath; 
        string fullPath = HttpContext.Current.Request.MapPath(appPath) + @"\avatar\"; 
        hpFile.SaveAs(Server.MapPath("~/" + uniqName)); 
        Response.ContentType = "text/plain"; 
        Response.Write("test");  
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      Response.Write("test"); 
     } 
    } 

原因的FormsAuthenticationTicket目的是使用與Firefox的Uploadify時雖然通過認證的cookie。

我見過許多例子Response.Write返回一個值回onAllComplete事件。但我所得到的是未定義的。 我也曾嘗試使用Context.Response.Writethis.Response.WriteHttpContext.Current.Response.Write。他們都返回undefined。

任何幫助表示讚賞。 感謝

+0

當您設置上,如果(identity.IsAuthenticated)的斷點被擊中斷點? – Tony 2011-03-04 17:46:23

+0

我會添加一個'默認'響應.NET代碼,以確保正確的執行流程。您的調試還沒有排除所有選項。 – cusimar9 2011-03-04 18:09:32

+0

是的,identity.IsAuthenticated返回true並保存圖像。還有Response.Write(「test」);線在.NET代碼存在之前實際上被命中。 – Sivakanesh 2011-03-04 18:19:21

回答

-1

看來,onAllComplete事件永遠不會觸發。這可能是因爲我自動上傳單個文件而不是多個文件。 我發現onComplete事件觸發,我可以用它來代替。

+0

請將您的完整答案發布在這裏,因爲您已將其標記爲您帖子的「答案」。 – curiousBoy 2015-09-22 15:08:11