2012-03-01 35 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"]; 
}