2013-03-25 75 views
1

我爲客戶端從我的網站上下載內容(視頻)創建了一個HttpHandler(.ashx)。首先我使用WriteFile方法,我意識到它需要大量內存,然後決定將其更改爲TransmitFile方法。使用Response.TransmitFile時不能多次調用處理程序ashx

但是發生了一件奇怪的事情,我無法再做一次以上的下載。我不得不等待下載完成並啓動其他。

基本上代碼是這樣的:

 System.IO.FileInfo file = new System.IO.FileInfo(file_path); 

     context.Response.Clear(); 

     if (flagH264) 
     { 
      context.Response.ContentType = "video/mp4"; 
     } 
     else 
     { 
      context.Response.ContentType = "video/x-ms-wmv"; 
     } 

     context.Response.AddHeader("Content-Length", file.Length.ToString()); 
     context.Response.AddHeader("Content-Disposition", "attachment; filename=" + name); 

     //context.Response.WriteFile(file_path.Trim()); 
     context.Response.TransmitFile(file_path.Trim()); 
     context.Response.Flush(); 

任何人都可以知道這是什麼問題呢?

回答

0

我發現了什麼問題。

我用於下載頁面的HttpHandler(ashx)實現了一個接口IRequireSessionState,它給了我操作會話數據的讀/寫權限。使用TransmitFile方法時,IIS會阻止系統上的任何操作以保護會話數據不被更改。

溶液改變IRequireSessionStateIReadOnlySessionState,也就是說,只有讀訪問會話數據,也沒有必要提供任何形式的安全性,阻止用戶操作。

相關問題