. NET implements cross-Server File upload and download methods. net uploads and downloads

Source: Internet
Author: User

. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.