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")))
{ ... }
有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top