简体   繁体   English

Server.MapPath()返回与DirectoryInfo一起使用时不存在的路径

[英]Server.MapPath() returning a path that does not exist when used with DirectoryInfo

I have a virtual directory setup in IIS6. 我在IIS6中有一个虚拟目录设置。 This maps to a shared network drive. 这映射到共享的网络驱动器。

I can correctly map the path using 我可以使用正确地映射路径

string mappedPath = HttpContext.Current.Server.MapPath(path);

I then create a DirectoryInfo object as I want to find some files in the directory. 然后我要创建DirectoryInfo对象,因为我想在目录中找到一些文件。

DirectoryInfo updateDirectory = new DirectoryInfo(mappedPath);

But then updateDirectory.Exists is false?? 但是然后updateDirectory.Exists是假的吗? I can take the string from the mappedPath and copy into Start->Run to get to the path so I know it exists. 我可以从mappedPath获取字符串,然后复制到Start-> Run中以获取路径,因此我知道它存在。 I am authenticating to the webservice using integrated windows authentication and have permissions to the necessary folders. 我正在使用集成的Windows身份验证对Web服务进行身份验证,并具有对必要文件夹的权限。

Is there something obvious I'm missing in the code? 代码中我明显缺少什么吗? Or is this purely set-up and configuration of IIS etc.? 还是这纯粹是IIS等的设置和配置?

You need to check whether your service working process account has access rights to that folder. 您需要检查您的服务工作流程帐户是否对该文件夹具有访问权限。 AFAIK windows authentication does not bring impersonation to the working process so it can be different with your windows acct. AFAIK Windows身份验证不会给工作过程带来模仿,因此Windows身份验证可能会有所不同。 Alternatively (just to prove account issues) you can run the app pool using your account to see if problem will go away. 或者(仅为了证明帐户问题),您可以使用您的帐户运行应用程序池,以查看问题是否会消失。

According to this link: 根据此链接:

http://bytes.com/topic/asp-net/answers/471616-server-mappath-virtual-directories http://bytes.com/topic/asp-net/answers/471616-server-mappath-virtual-directories

Server.MapPath doesn't give expected output when used against virtual directories. 当对虚拟目录使用Server.MapPath ,不会提供预期的输出。

If it is server permissions and you are using Windows Authentication, make sure you have this in your config: 如果这是服务器权限,并且您正在使用Windows身份验证,请确保在配置中包含此权限:

<identity impersonate="true" /> 

DirectoryInfo returns false on error conditions: if the folder isn't there; 如果出现错误情况,DirectoryInfo返回false:如果文件夹不存在; you don't have permissions; 您没有权限; or it's a disconnected network folder. 或它是断开连接的网络文件夹。

Sounds like permissions of your ASP.NET worker process to me - the impersonation will solve this. 听起来像是您的ASP.NET辅助进程的权限对我来说-模拟将解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM