System.IO.DirectoryInfo 的奇怪行为。存在功能
我正在使用 c# 和 asp 开发一个应用程序。它需要访问本地网络中的某些地方。表单中有一个文本框,它接受用户要访问的路径并将其存储到名为 location 的字符串变量中。
如果应用程序在 Windows 7 中运行,则 if 循环始终返回 false,并且仅当我从已安装的应用程序运行时才会发生这种情况,否则如果路径为 true,它将返回 true。代码如下:
文本框 BackupLocation 的输入如下所示
\\192.168.0.33\Others (F)
。如果应用程序托管在 Windows XP 系统上,则可以正常工作
System.IO.DirectoryInfo locationInfo = new System.IO.DirectoryInfo(BackupLocationTxt.Text);
if (locationInfo.Exists) // always return false if the application run in windows 7
{
}
为什么会发生这种情况?
I am developing an application using c# and asp. It need to access some places in the local network . There is a text box in the form which accept the path to be accessed from the user and will store it to a string variable named location.
The if loop always return false if the application run in windows 7. and it occurs only when I run from the installed application, otherwise it will return true if the path is true. Here is the code:
The input to textbox BackupLocation is like this
\\192.168.0.33\Others (F)
. It work fine if the application is hosted on a system which have windows XP
System.IO.DirectoryInfo locationInfo = new System.IO.DirectoryInfo(BackupLocationTxt.Text);
if (locationInfo.Exists) // always return false if the application run in windows 7
{
}
Why this happens ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发生这种情况是因为您运行应用程序的用户无权读取这些文件夹。您可能需要向运行站点的帐户授予对这些文件夹的读取权限。
This happens because the user you are running your application under doesn't have authorization to read those folders. You might need to grant read access to those folders to the account you are running your site under.
尝试使用 System.IO.Directory.Exists(string path) 代替。
Try
System.IO.Directory.Exists(string path)
instead.您的 ASP.NET 应用程序没有访问本地网络中其他计算机上的文件夹的权限。
尝试使用在 LocalService 帐户下启动的 Windows 服务。
Your ASP.NET application doesn't have permissions to the folder on other computer in local network.
Try use windows service started under LocalService account.