Author: tonnyEMAIL: webmaster@weiw.com reprint please show the source: http: //www.weiw.com
Environmental description:
Two servers in the LAN, a main web server, a file server, two server operating system for Win2000 Professional (or win2000 server) main web server LAN internal URL: http: // main: 8080 external URL server The computer name is: the port of the main Web site is 8080
Document server LAN internal URL: http: // file: 8080 server computer name: port of File Web site is 8080
Demand introduction: Visitors Access the web server and place the file in the file server when uploading the file, such as generating some information, and is generated on the file server. The web server does not retain file replica. And allow files to generate an ASPX format.
Workaround: File Server IIS Sets the site. HTTP: // File: 8080, set a directory to store upload files, named UPFile. And add the current directory properties -> security -> permissions to a pre- to dedicated domain user accounts, and permissions is of course fully controlled.
On the web server, there is a UPFILE directory in the root directory. This directory is now removed from IIS, and then establishes a virtual directory in IIS, named UPFile, the target points to the UPFile directory on the file server. Of course, add-on-readable permissions.
Upload the file to the file server program: Test.cs (program running on the web server) Using system.text;
String VirtualPath = "TEST01"; // To build folder names in the UPFILE directory; string rootupfilepath = @ "http: // file: 8080 / upfile /"; // file server (server running server) String Uristring = rootupfilepath virtualpath "/"; // URL path
/RCreatedIRectory.aspx This file is used to establish a corresponding directory in the UPFILE directory on the destination server (file server). String path = rootupfilepath "createdirectory.aspx? path =" VirtualPath;
String filename = "Test.htm"; // This is the name of the file
String mystring = "This is the content of the file"; UTF8ENCODING AE = New utf8encoding ();
BYTE [] INPUT = ae.getbytes (mystring); int rtLength = INPUT.LENGTH;
String username = @ "domain_a / cqweb"; // "Domain Name / Domain User Name" String Password = @ "123456"; // domain user password
System.net.networkcredential mycred = new system.net.networkcredential (username, password); // Provide credentials for password-based authentication schemes system.net.WebClient Client = new system.net.webclient (); // Provide URI identified resources send data and public methods for receiving data from the URI identified resource system.net.credentialcache mycache = new system.net.credentialCache (); // Store credentials for Internet resources Mycache.Add (new uri (uri (uri), "Ntlm", mycred; // Add a networkcredential instance by cache to the credentials [] buffer = new byte [128];
Street.Openread (PATH); stream.read (buffer, 0, 128); // Create a directory
System.io.Stream WriteStream = Client.OpenWrite (Uristring FileName, "Put"); WriteStream.write (INPUT, 0, INTLENGTH); WRITESTREAM.CLOSE ();
Files CREATEDIRECTORY.ASPX <% @ page language = "c #"%>