標籤:技術分享 檔案 [] 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檔案跨伺服器上傳下載