Directory.Exists不工作的网络路径 [英] Directory.Exists not working for a network path

查看:1465
本文介绍了Directory.Exists不工作的网络路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如果目录中存在的代码行检查,然后让在它的文件列表。

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

System.IO.Directory.Exists(@"\\Server\Folder\");



我的作品时,我测试(从Visual Studio运行),但是当我部署的网站,它始终返回false。

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

我做同样验证另一个文件夹,另一台服务器上(假设服务器2),它工作正常。

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?

推荐答案

当您运行Visual Studio中的代码,它运行在您的用户的权限。

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

在运行该代码在IIS中它的应用程序池的身份在缺省情况下是内置的用户运行网络服务,这是不具有本地计算机的外部访问本地用户帐户。

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.

在网络共享上的权利是第一层,即在目录上的NTFS权限检查之后。

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.

这篇关于Directory.Exists不工作的网络路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆