. NET implements cross-Server File upload and download methods. net uploads and downloads
Environment Description
The two servers are A, B, and B.
Implementation Method
1. Create A dockeruser On A and B. The user name and password must be consistent.
2. Set the attachment folder Attachments sharing on server B, add the user dockers user, and set the read and write permissions.
3. Run "\ IP \ Attachments" in the "A" dialog box and enter the user name and password to test whether the sharing is successful. If the sharing is unsuccessful, check the network and configuration problems.
4. Modify the value of the path node of the AWeb. config file.
<Add key = "key value" value = "\ IP address \ Attachments"/>
5. Add the following configuration under the <system. web> node. the username and password must be consistent with the created shared account.
<Identity impersonate = "true" userName = "doc127user" password = "password"/>
Upload test successful! Download error:
The download method is as follows:
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);
Modify the download method:
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"; // notify the browser to download the file instead of opening Response. addHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. urlEncode (fileName, System. text. encoding. UTF8); context. response. binaryWrite (bytes); context. response. flush (); context. response. end ();
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.