简体   繁体   中英

Directory.Exists() strange behavior

I have an IIS-hosted WCF service and I am trying to use Directory.Exists() method. If nonexistent network location is passed, this method hangs. I've googled for it and found that it's "kind of ok" due to Directory.Exists() inner implementation. But I wrote a simple console application which does the same and Directory.Exists() never hangs, always returns ' false '. I run the application under my (admin) account and IIS pool is running under 'Network Service'.
Do you have any ideas why? What is the difference between doing the same inside a service or a console application?

This might be caused due to user authorization control stuff that is present in Windows (remember when you try to access a folder that you dont have access in Windows? It kind of waits a long time to answer "You can't access,..." or something like that).

Which is the user you are running the application? Your user id (as per what you said you can access that folder running the console application) is able to see that folder.

So, try to run the application as your own user id.

Furthermore, check this link: https://stackoverflow.com/a/21385162/1378854

Are you sure the application is running as Network Service? A local Network Service account won't have access to the network.

Use the UNC path instead of a mapped network drive, as the mapped drive is specific to your user account. Also, as KMan pointed out, make sure the application pool identity has access to the UNC path destination.

please visit this link:

http://msdn.microsoft.com/en-us/library/ff649309.aspx How to get working path of a wcf application?

thanks.

The key here is really about running on Network Service vs. the admin account.

You know the later can acceess the network location, but you are not really sure if the earlier can.

Here is one example of a case where you could be expecting there is access, but it doesn't really work: https://serverfault.com/a/177150

The fact that the machine with the shared drive is not on a domain is where your main problem is

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