.NET檔案跨伺服器上傳下載

來源:互聯網
上載者:User

標籤:技術分享   檔案   []   images   string   環境   pca   div   span   

環境說明:兩台伺服器伺服器為A,伺服器為B,伺服器B為檔案伺服器1、在A和B上建立使用者docshareuser,使用者名稱和密碼保持一致2、B伺服器上設定附件檔案夾Attachments共用,添加使用者docshareuser並設定讀寫權限 3、在A上運行框輸入”\\IP\Attachments”,輸入使用者名稱密碼測試是否共用成功,共用不成功請檢查網路及配置問題4、修改AWeb.config檔案附件路徑節點的值
<add key="索引值" value="\\IP地址\Attachments" />
5、在<system.web>節點下添加如下配置,使用者名稱密碼與建立的共用帳號保持一致
<identity impersonate="true" userName="docshareuser" password="密碼" />

測試上傳成功!下載時報錯:

因為下載的方法如下:

                context.Response.AppendHeader("Content-Length", fileSize.ToString());                context.Response.CacheControl = HttpCacheability.Public.ToString();                context.Response.Cache.AppendCacheExtension("max-age=" + 365 * 24 * 60 * 60);                context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));                context.Response.AppendHeader("ETag", "Never_Modify");                context.Response.Cache.SetETag("Never_Modify");                context.Response.Cache.SetLastModified(DateTime.Now.AddMinutes(-1));                context.Response.TransmitFile(filePath);

修改下載方式:

FileStream fs = new FileStream(filePath, FileMode.Open);                byte[] bytes = new byte[(int)fs.Length];                fs.Read(bytes, 0, bytes.Length);                fs.Close();                Response.ContentType = "application/octet-stream";                //通知瀏覽器下載檔案而不是開啟                  Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));                context.Response.BinaryWrite(bytes);                context.Response.Flush();                context.Response.End();  

  

.NET檔案跨伺服器上傳下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.