Sometimes we need to upload files from the client to the Web server side and store them in a Third-party file server on the service side.
implemented as follows :
1. Establish a shared folder on file Server B and create a user on that server, such as Docshareuser, to assign this user read and write permissions to the shared folder
2, on the Web server A also build a user with the same name Docshareuser (note that username and password must be consistent)
3, add a virtual directory under the Web site, the virtual directory of the physical path to execute server A shared directory, the path to meet the UNC rules, such as \\ServerB\DocShare, pass the authentication user set to the default.
4, trust relationship permissions, only on the basis of building trust, you can upload files to B server, the problem can be solved in two ways,
Mode 1: In web.config to increase the running analog account <identity impersonate= "true" Username= "Docshareuser" password= "password"/>
Mode 2: Load in Global.asax, the website automatically establishes the trust relationship when running, System.Diagnostics.Process.Start ("Net.exe", "Use \\\\b server ip\\ shared folder \" b Server password \ "/user:\" "" "" "" "" "" "" "" "" "," B "the user on the server refers to the user who can write to the shared folder (recommended use this way, will not affect the site certification changes)
5, Step 4 if take Web.config to add the simulation account way, then need to give C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary asp.net The files temp directory assigns the read and write control rights of the built user Docshareuser (the path is dependent on the installation framework version)
6, the code through the Server.MapPath ("virtual directory") way to obtain the upload address, write file flow can
7, note that the upload file IIS has a default 4M limit, can be modified by web.config, as follows
Copy Code code as follows:
The above verification is passed under WIN2008R2+IIS7.