MVC埰坑日記 檔案許可權

來源:互聯網
上載者:User

標籤:

  public static void DownLoadFile(string FileFullPath)        {            if (!string.IsNullOrEmpty(FileFullPath) && FileExists(FileFullPath))            {                FileInfo fi = new FileInfo(FileFullPath);//檔案資訊                FileFullPath = HttpUtility.UrlEncode(Path.GetFileName(FileFullPath)); //對檔案名稱編碼                FileFullPath = FileFullPath.Replace("+", "%20"); //解決空格被編碼為"+"號的問題                HttpContext.Current.Response.Clear();                HttpContext.Current.Response.ContentType = "application/octet-stream";                HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileFullPath);                HttpContext.Current.Response.AppendHeader("content-length", fi.Length.ToString()); //檔案長度                int chunkSize = 102400;//緩衝區大小,可根據伺服器效能及網路情況進行修改                byte[] buffer = new byte[chunkSize]; //緩衝區                using (FileStream fs = fi.Open(FileMode.Open))  //開啟一個檔案流                {                    while (fs.Position >= 0 && HttpContext.Current.Response.IsClientConnected) //如果沒到檔案尾並且客戶線上                    {                        int tmp = fs.Read(buffer, 0, chunkSize);//讀取一塊檔案                        if (tmp <= 0) break; //tmp=0說明檔案已經讀取完畢,則跳出迴圈                        HttpContext.Current.Response.OutputStream.Write(buffer, 0, tmp);//向用戶端傳送一塊檔案                        HttpContext.Current.Response.Flush();//保證緩衝全部送出                        Thread.Sleep(10);//主線程休息一下,以釋放CPU                    }                }            }        }

  這是從某項目當中找到的一段代碼
      在本機和測試環境  調用沒有問題

      在實際生產環境當中  IIS給了檔案夾  USERS和IIS_IUSRS 讀取許可權   結果怎麼都無法下載檔案
      原因:FileMode.Open 需要寫入許可權

 

MVC埰坑日記 檔案許可權

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.