Directory.Exists用于ASP.NET中的网络路径 [英] Directory.Exists for network paths in ASP.NET

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

问题描述

我想获得:

Directory.Exists(@"E:\subdirectory")

从ASP.NET运行时返回true,当E:是持久映射网络驱动器时。我使用以下命令从我的用户上下文中运行的命令行映射它,该命令行成功返回并且不提示输入凭据:

to return "true" when running from ASP.NET when E: is a persistent mapped network drive. I used the following command to map it from a command line running under the context of my user, which returns successfully and does not prompt for credentials:

net use E: \\servername\sharename /persistent:yes

At这一点我完全在本地运行。

At this point I'm running entirely locally.

当我从控制台应用程序或linqpad运行Directory.Exists行时,它返回true。当我从在IIS下运行的ASP.NET应用程序( IIS express)运行它时,它返回false。

When I run the Directory.Exists line from a console app or linqpad, it returns true. When I run this from an ASP.NET application running under IIS (not IIS express), it returns false.

我已经更改了我的应用程序池使用我在本地运行的同一用户帐户。我已经验证这已生效:

I have changed my application pool to use the same user account I run as locally. I've verified this has taken effect by:


  • 检查我的Windows进程列表并确保w3wp.exe在我的用户帐户下运行。

  • 将我的ASP.NET应用程序附加到w3wp.exe并设置断点,然后检查Environment.UserName和Environment.UserDomainName以验证我是否在我的用户帐户的上下文中运行。

但是,在检查网络共享时,我的ASP.NET应用程序仍然返回false。

However, my ASP.NET application still returns false when checking for the network share.

为什么会这样?

推荐答案

映射的网络驱动器与用户会话相关联。 IIS在会话0中运行,您的映射驱动器很可能在会话1中运行。

Mapped network drives are tied to the user session. IIS is running in session 0, your mapped drive is running in most likely session 1.

我不知道是否有任何方法可以让网络驱动器出现在其他会话中当你为你的会话创建它们时,我认为你不需要使用 E:\ 而是使用 \\servername \ sharename 表示路径。

I don't know of any way to make network drives show up for other sessions when you create them for your session, I think you will need to not use E:\ and instead use \\servername\sharename for the path.

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

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