简体   繁体   中英

Read/write files in shared drive from web application hosted on iis

We have two server in same domain. On one server (SERVER1) we have folder "C:\\AppFiles\\Production\\Inbound" and shared AppFiles folder as a drive (AppFiles (O:)) to another server (SERVER2) and we are manually able to place files in shared drive (O:\\Production\\Inbound) on SERVER2. But we want to read/write files in shared drive (O:\\Production\\Inbound) from our mvc web application hosted on SERVER2.

We are getting below error in provided code when try to read/write in shared drive (O:\\Production\\

 public void Writefile()
 {
  System.IO.File.WriteAllText(Path.Combine(@"O:\Production\Inbound", "testlog.txt"), "test test, text");
 }

error:

Could not find a part of the path 'O:\\Production\\Inbound\\testlog.txt'.

Please suggest how i can read/write files in shared drive from application hosted on iis.

Mapped drives are not supported on IIS, rather you can use UNC paths. Try changing the path to the following:

\\SERVER1\C$\AppFiles\Production\Inbound

If both the servers are on the same network and you can access the above link from server 2, the it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM