2012-03-01 36 views
0

我想跟蹤我的電子商務網站的產品下載的完整/成功與失敗。我使用asp.net處理程序,我通過jquery ajax.i寫了一個代碼。但下載對話框沒有彈出,我仍然不知道成功和失敗statistics.i需要更新我的數據庫基於返回的json數據(true爲成功/ false爲失敗)從asp.net處理程序.Anyone幫幫我。我所指的鏈接是跟蹤產品下載的成功與失敗

http://www.codeguru.com/csharp/csharp/cs_data/article.php/c17133/Tip-File-Download-in-ASPNET-and-Tracking-the-Status-of-Success-or-Failure-of-Download.htm

+0

如果是這樣,你可以限制下載嘗試次數 - 看到它是微不足道的複製下載的文件,我沒有看到的一點。在服務器無法捕捉的情況下(如「磁盤已滿」或寫入錯誤),客戶端可能會發生很多錯誤。我只是激活下載一段時間(比如,24小時),並沒有做任何成功的檢查。 – 2012-03-01 09:58:46

回答

0
//Assuming Download() is a thread 

Private void DownLoad() 
{ 
    try 
    { 
     for(int i=0;i<=n;i++) 
     { 
      //Your code 
      Session["CurrentStatus"] = "SUCCESS"; //you can set download percentage here 
     } 
     Session["CurrentStatus"] = "COMPLETE"; 
    }catch() 
    { 
     Session["CurrentStatus"] = "FAIL"; 
    } 
} 


From Your UI you will fire an asynchronous event using PageMethod i.e 

function GetCurrentThreadStatus() 
{ 
     //You can use JQuery Ajax here 
     //PageMethod is just an alternative 
     PageMethods.GetThreadStatus(function(status){ 
      // success 
      if(status=="COMPLETE") 
      { 
       //Update DB :: success 
      } 
      if(status=="FAIL") 
      { 
       //Update DB :: fail 
      } 
     }); 
} 
Code Behind : C# 

[WebMethod] 
public static string GetThreadStatus() 
{ 
    return (string)Session["CurrentStatus"]; 
}