Asp. NET writes files to another server (text tutorial) and notes _ practical Tips

Source: Internet
Author: User

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.

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.