ASP. NET writes files to another server (Graphic tutorial) and precautions

Source: Internet
Author: User

Sometimes we need to upload files from the client to the WEB server and store the files on the server to a third-party file server for storage.

The implementation is as follows::

1. Create a shared folder on file server B, and create a user, such as doc‑user, on the server to assign the read and write permissions to the shared folder.

2. Create A dockeruser with the same name on WEB server A (note: the user name and password must be consistent)

3. Add A virtual directory under the website. The physical path of the virtual directory executes the shared directory of server A. The path complies with UNC rules, such as \ ServerB \ DocShare, set the pass-on authentication user to the default value.

4. the trust relationship permission can only upload files to server B Based on the trust established. This problem can be solved in two ways,

Method 1: Add a simulated account in Web. Config <identity impersonate = "true" userName = "DocShareUser" password = "password"/>

Method 2: In Global. when asax is loaded, the website Automatically Establishes a trust relationship as soon as it is run. diagnostics. process. start ("net.exe", "use \ B server IP \ Shared Folder \" B server password \ "/user: \ "username on server B \"). The user on server B is the user who can write the shared folder (this method is recommended and will not affect the changes of website authentication)

5. Step 4: Use Web. to add a simulated account in Config, you need to give C: \ Windows \ Microsoft. NET \ Framework64 \ v4.0.30319 \ Temporary ASP.. NET Files temporary directory is assigned the read and write permissions of the created user dockers user (The Path depends on the version of the Framework installed)

6. Use Server. MapPath ("virtual directory") in the code to obtain the upload address and write it to the file stream.
7. Note that IIS has a default 4 m limit for uploading files, which can be modified through WEB. config, as shown below:

Copy codeThe Code is as follows: The above verification is passed in WIN2008R2 + IIS7.

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.