Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

c# - Directory.Exists not working for a network path

I have a line of code checking if a directory exists and then getting the list of files in it.

System.IO.Directory.Exists(@"\ServerFolder");

I works when I test it (run from visual studio), but when I deploy the web site, it always returns false.

I do the same verification for another folder, on another server (let's say Server2) and it works fine.

I then thought it was an access issue, but the shared folder and network have all access to everyone... Is there another reason why it would not work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you run the code in Visual Studio it runs under the the rights of your user.

When you run the code in IIS it runs in the identity of the Application Pool which by default is the built in user "Network Service" this is a local user account which does not have access outside the local machine.

The rights on the network share are the first layer, after that the NTFS rights on the directory are checked.

You need to change the identity of the application pool to a domain user with the same rights as your user.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...