Asp. NET writes files to another server

Source: Internet
Author: User

Sometimes we need to upload the files from the client to the Web server side and store the files on the server to the third-party file servers.

The implementation is as follows:

1. Create a shared folder on file Server B while creating a user on the server, such as Docshareuser, to assign read and write permissions to the shared folder to this user

2, on the Web server A also to build a same name user Docshareuser ( Note that the user name and password must be consistent )

3, add a virtual directory under the Web site, the physical path of the virtual directory to execute Server A shared directory, the path conforms to the UNC rules, such as \\ServerB\DocShare, pass authentication user set to default.

4, the trust relationship rights, only on the basis of building trust, you can upload files to B server, the problem can be resolved in two ways,

Mode 1: Add run Demo account in Web. config <identity impersonate= "true" Username= "docshareuser" password= "password"/>

Mode 2: Load in Global.asax, the site is run automatically establish trust relationship, System.Diagnostics.Process.Start ("Net.exe", "Use \\\\b server ip\\ shared folder \" b Server password \ "/user:\" (User name \ "" on Server B), user on Server B refers to the user who can write to that shared folder (this method is recommended and does not affect site certification changes)

5. Step 4 If you add the analog account method in Web. config, you need to give C:\Windows\Microsoft.NET\Framework64\v4.0.30319\temporary ASP . Temporary directory assignment user Docshareuser read and write control permissions (path depends on installation framework version)

6, the code through the Server.MapPath ("virtual directory") way to obtain the upload address, write to the file stream can

7, note that the upload file IIS has a default 4M limit, can be modified via Web. config, as follows

The above is validated under WIN2008R2+IIS7.

Asp. NET writes files to another server

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.