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.