0

My website is published under c:\inetpub\wwwroot folder and I have some large text files on D: drive that I need to access. Let's say the exact location is D:\Test\test.txt. When my website runs it keeps failing on the File.Exists() check. I have tried the following but none worked:

  • Created virtual dir from IIS to point to this folder and used Server.MapPath in code
  • Gave Network Service read access to this Test folder
  • Shared the folder with Network Service and in the website reference the UNC path

All of the above failed and the site still says the file doesn't exist, but it's there. Any ideas?

EDIT: Below are several attempts that I placed in Page_Load which failed:

if (File.Exists(@"D:\Test\test.txt"))
{ ... }

if (File.Exists(Server.MapPath("TestVirtualDir/test.txt")))
{ ... }
user1715925
  • 607
  • 9
  • 26
  • Can you setup a symlink under wwwrooot to d:\? http://stackoverflow.com/questions/9042542/what-is-the-difference-between-ntfs-junction-points-and-symbolic-links – rene Feb 23 '13 at 19:17
  • I can try that, however is it necessary? It seems like I should be able to access the D:\ files much more easily... – user1715925 Feb 23 '13 at 19:28
  • Based on what you already tried I reckoned you were out-of-options...I recall that iis doesn't like to wander off to other paths not under the application path. Maybe you should share the code/markup you use to serve those files on D:\ – rene Feb 23 '13 at 19:40
  • If you add a Trace.Write(Server.MapPath("TestVirtualDir/test.txt")) hit the page and see what is in trace.axd? The persmission you write are read, did you also give execute and list foldercontent? Are your sure Network Service is the identity that is used in the appdomain? – rene Feb 23 '13 at 20:28
  • I verified that Server.MapPath points to the correct physical location. I'm pretty sure Network Service is used since I remember having to add this permission for a different website on the same server, how do I double check this? – user1715925 Feb 23 '13 at 22:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25034/discussion-between-rene-and-user1715925) – rene Feb 24 '13 at 10:29
  • I checked and turned out you were right, it was using a different user acount under IIS user something instead of network service. go ahead and add a comment so I can mark it as answer. – user1715925 Feb 25 '13 at 19:30

1 Answers1

0

Make sure Network Service is the identity that is used in the appdomain.

rene
  • 41,474
  • 78
  • 114
  • 152