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